Showing posts with label commanline arguments in cpp. Show all posts
Showing posts with label commanline arguments in cpp. Show all posts

Tuesday, December 14, 2010

Program to find odd and even numbers by using commandline arguments...

# include <iostream.h>
# include <conio.h>
# include <stdlib.h>
# include <string.h>
void main(int argc,char **argv)
{
int *a=new int[argc];
int even[10],j=0,odd[10],k=0,temp;
for(int i=1;i<argc;i++)
 {
 char *ar=argv[i];
 temp=0;
 for(int m=0;m<strlen(ar);m++)
 {temp=(temp*10)+ar[m]-48;}
 a[i-1]=temp;
 }

 for(i=0;i<argc-1;i++)
 if(a[i]%2==0)
 {
 even[j]=a[i];
 j++;
 }
 else
 {
 odd[k]=a[i];
 k++;}
cout<<"\nEven no.s\n";
for(i=0;i<j;i++)
cout<<even[i]<<" "<<endl;
cout<<"\nOdd numbers\n";
for(i=0;i<k;i++)
cout<<odd[i]<<" "<<endl;
getch();}

Intel Core i7 950 3.06GHz 8M L3 Cache LGA1366 Desktop Processor