Design a program using an array that lists even numbers and
odd numbers separately from the 12 numbers supplied by a user.
Answer Posted / dally
#include<stdio.h>
int main()
{
int n,i,j=0,k,count1=0,count2=0;
int a[10],b[10],c[10] ;
printf("Enter value for n\n");
printf("Enter value for array");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i] % 2== 0){
count1++;
b[j] = a[i];
j++;
}
else
{
count2++;
c[j] = a[i];
j++;
}
}//End of forloop
j=0;
while(b[j] != '\0')
printf("Even nubers %d\n",b[j]);
printf("No of Even numbers\n");
k =0 ;
while(c[k] != '\0')
printf("Odd nuber %d\n",c[k]);
printf("No of Odd numbers\n");
}
| Is This Answer Correct ? | 6 Yes | 12 No |
Post New Answer View All Answers
How can you restore a redirected standard stream?
How a string is stored in c?
What are logical errors and how does it differ from syntax errors?
What is the difference between Printf(..) and sprint(...) ?
how can I convert a string to a number?
what is recursion in C
What is #ifdef ? What is its application?
What are the advantages and disadvantages of c language?
how should functions be apportioned among source files?
Explain the use of fflush() function?
Differentiate between #include<...> and #include '...'
What is malloc and calloc?
How can a program be made to print the line number where an error occurs?
FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above
What is scanf_s in c?