Skip to main content

C++ program to extract the elements in the odd positions of an array

C++ program to extract the elements in the odd positions of an array that are stored into an another array.

This is very easy to do. 

//program to extract elements in the odd positions

#include<conio.h>
#include<iostream.h>
#include<stdio.h>
#include<string.h>

class extract
{
public: char sent[25],extd[25];
int l;
void get()
{
cout<<"\nType the sentance:\n"<<endl;
gets(sent);
cout<<"OK"<<endl<<endl;
}
int filter();
void disp(int r);

};
int extract::filter()
{
int i,j;
l=strlen(sent);
for(j=0,i=0;i<l;i=i+2,j++)
{
extd[j]=sent[i];
}
return j;
};
void extract::disp(int r)
{
int i;
for(i=0;i<r;i++)
cout<<extd[i];
};
void main()
{
clrscr();
extract t;
t.get();
int g=t.filter();
t.disp(g);
getch();
}

__________________________________________________

try this and share it!

Comments

Popular posts from this blog

Talky Messenger Documentation & Setup

( Github ) Just created a chat app that runs in Node and Socket. the attempt was worthy. Talky is a messenger app built with Node, Express, Socket, Angular & Bootstrap. It's like a server-client structure. (But obviously not like the one we done at OS lab using shared memory). It has a broadcasting structure. Talky does not keep a log on chat. i.e., It doesn't have a memory or database. When we close the browser window, chat history is lost. There I also added a basic console, protected by a password, to send real-time notifications to active clients. The name 'Talky' was suggested by a friend of mine. (hey, thank you for that. The fact is that I am not really good at naming...😝) What if sometimes your college blocks WhatsApp? Try Talky. ( There is also a website on internet in the name of 'Talky' which has no connection with this one. ) Download Talky Messenger To use Talky, all you need is 3 things: Node server Source code...

The Language Evaluation Criteria

There are a vast amount of programming language that we are using. Some are designed to accomplish some specific task. Some are for common uses. Any way the below described is a short ‘summery’ of the criteria we followed to evaluate the language. Overview 1.        Readability a.        Overall Simplicity b.       Orthogonality c.        Data Types d.       Syntax Design 2.        Writability a.        Simplicity and Orthogonality b.       Support for Abstraction c.        Expressivity 3.        Reliability a.        Type Checking b.       Exception Handling c.        Aliasing d.       Readability ...