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

Why c is called object oriented language?

0 Answers  


What is pointer to pointer in c with example?

0 Answers  


What is meant by recursion?

0 Answers   ADP,


write aprogram for There is a mobile keypad with numbers 0-9 and alphabets on it. take input of 7 keys and then form a word from the alphabets present on those keys.

1 Answers   iGate, Shashi, Source Bits, Subex,


What is file in c preprocessor?

0 Answers  






Discuss similarities and differences of Multiprogramming OS and multiprocessing OS?

4 Answers   TCS,


what is constant pointer?

3 Answers  


what is use of loop?

10 Answers   Infosys,


HOW TO FIND OUT THE RREVERS OF A GIVEN DIGIT NUMBER IF IT IS INPUT THROUGH THE KEYBORD BY USING C LANGUAGE

3 Answers   Wipro,


If fflush wont work, what can I use to flush input?

0 Answers  


Differentiate between static and dynamic modeling.

0 Answers   Wipro,


Explain the properties of union.

0 Answers  


Categories