in reply to Re: New student, can we write this program in perl...
in thread New student, can we write this program in perl...
Thank you Choroba Sir for your interest , please have a look at C code.
It will basically input an array of 'n' numbers and then separate it into two arrays, one contains odd numbers and one contains even numbers. Hoping to hear from you soon.#include<stdio.h> #include<conio.h> void main() { int a[20],b[20],c[20],i,j=0,k=0,n; clrscr(); printf("Enter the number of elements"); scanf("%d",&n); printf("Enter n numbers\n"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { if((a[i]%2)==0) { b[j]=a[i]; j++; } else { c[k]=a[i]; k++; } } printf("The even numbers are\n"); for(i=0;i<j;i++) { printf("%d\n",b[i]); } printf("The odd numbers are\n"); for(i=0;i<k;i++) { printf("%d\n",c[i]); } getch(); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: New student, can we write this program in perl...
by choroba (Cardinal) on Oct 19, 2012 at 17:15 UTC | |
Re^3: New student, can we write this program in perl...
by Jenda (Abbot) on Oct 22, 2012 at 23:23 UTC |
In Section
Seekers of Perl Wisdom