Design a program using an array that lists even numbers and
odd numbers separately from the 12 numbers supplied by a user.

Answers were Sorted based on User's Feedback



Design a program using an array that lists even numbers and odd numbers separately from the 12 numb..

Answer / belsia

#include<stdio.h>
#include<conio.h>
void main()
{
int a[12],b[12],c[12],i,j=0,k=0;
clrscr();
printf("Enter 12 numbers\n");
for(i=0;i<12;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<12;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();
}

Is This Answer Correct ?    66 Yes 21 No

Design a program using an array that lists even numbers and odd numbers separately from the 12 numb..

Answer / valli

main()
{
int a[12],j;
printf("enter 12 numbers");
for(i=0;i<12;i++)
scanf("%d",&a[i]);
printf("even numbers\n");
for(i=0;i<n;i++)
if(a[i]%2==0)
printf("%d ",a[i]);
printf("odd numbers\n");
for(i=0;i<12;i++)
if(a[i]%2)
printf("%d ");
}
printf("%d ",a[i]);

Is This Answer Correct ?    15 Yes 16 No

Design a program using an array that lists even numbers and odd numbers separately from the 12 numb..

Answer / atul shukla

in list 12 all can be even or all can be odd so it require
3 array of same size

#include<stdio.h>
void main()
{
int a[12],even[12],odd[12],i,c=0,d=0;
printf("enter 12 numbers");
for(i=0;i<12;i++)
scanf("%d",&a[i]);
for(i=0;i<12;i++)
(n[i]%2==0)?even[c++]=a[i]:odd[d++]=a[i];
printf("seprate list of odd entries");
for(i=0;i<=d;i++)
printf("%d",odd[i]);
printf("seprate list of even entries");
for(i=0;i<=d;i++)
printf("%d",even[i]);
}

Is This Answer Correct ?    2 Yes 6 No

Design a program using an array that lists even numbers and odd numbers separately from the 12 numb..

Answer / vignesh1988i

in the above program the last for loop is LOGICALLY WRONG
one...... the last forloop must be changed as...


I WILL COME WITH A ANSWER AS SOON AS POSSIBLE

Is This Answer Correct ?    7 Yes 12 No

Design a program using an array that lists even numbers and odd numbers separately from the 12 numb..

Answer / 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

Design a program using an array that lists even numbers and odd numbers separately from the 12 numb..

Answer / prakash.

/* program to print even nums in even position,odd in odd
position*/
/* Ex: 2 1 3 4 output:2 1 4 3*/
/* work for almost all check it if any wrong*/
#include<stdio.h>
#include<conio.h>

void main()
{
int a[4],j=0,i;
int b[4],e=0,od=1;
clrscr();
for(i=0;i<4;i++)
{
printf("Enter A number : ");
scanf("%d",&a[i]);
}
for(i=0;i<4;i++)
{
if((a[i]%2)==0)
{
j=e;
b[j]=a[i];
e=j+2;
}
else
{
j=od;
b[j]=a[i];
od=od+2;
}
}
for(j=0;j<4;j++)
{
printf("%d\n",b[j]);
}
getch();
return;
}

Is This Answer Correct ?    4 Yes 11 No

Design a program using an array that lists even numbers and odd numbers separately from the 12 numb..

Answer / vignesh1988i

A SMALL FLOWER BRACES IS LEFT.......

THE FOLLOWING IS THE RIGHT PROGRAM


#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],*ptr[50],count=0,n,flag=1;
printf("enter the max. elements to be entered :");
scanf("%d",&n);
int k=0;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]%2!=0)
{
ptr[k]=&a[i];
count++;
k++;
}
else
flag=0;
}
printf("odd numbers :\n");
for(i=0;i<count;i++)
printf("%d\n",*(*(ptr+i)));
if(flag==0)
{
printf("even numbers :\n");
for(i=0;i<n;i++)
{
if(ptr[i]!=&a[i])
printf("%d\n",a[i]);
}
}
getch();
}

Is This Answer Correct ?    2 Yes 12 No

Design a program using an array that lists even numbers and odd numbers separately from the 12 numb..

Answer / vignesh1988i

A SMALL IMPLEMENTATION OF POINTERS

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],*ptr[50],count=0,n,flag=1;
printf("enter the max. elements to be entered :");
scanf("%d",&n);
int k=0;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]%2!=0)
{
ptr[k]=&a[i];
count++;
k++;
}
else
flag=0;
printf("odd numbers :\n");
for(i=0;i<count;i++)
printf("%d\n",*(*(ptr+i)));
if(flag==0)
{
printf("even numbers :\n");
for(i=0;i<n;i++)
{
if(ptr[i]!=&a[i])
printf("%d\n",a[i]);
}
}
getch();
}


thank you

Is This Answer Correct ?    3 Yes 15 No

Post New Answer

More C Interview Questions

main() { int i,n=010; int sum=0; for(i=1;i<=n;i++) {s=s+i; } printf("%d",&s); getch(); }

6 Answers  


Do you have any idea how to compare array with pointer in c?

0 Answers  


What is the use of a static variable in c?

0 Answers  


What is wrong in this statement?

0 Answers  


What is a protocol in c?

0 Answers  






Is it fine to write void main () or main () in c?

0 Answers  


write a program without using main function?

2 Answers   TCS,


what is the output of the following program? main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }

7 Answers  


#include<stdio.h> void main() { char *str; long unsigned int add; str="Hello C"; add=&str[0]; printf("%c",add); } What is the output?

4 Answers   Infosys,


What does 3 periods mean in texting?

0 Answers  


main() { int i=5; printf("%d%d%d%d",i++,i--,i); }

10 Answers  


Write a progarm to find the length of string using switch case?

0 Answers   TCS,


Categories