Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1- write a program in C language that will prompt the user to enter 10 integers

ID: 3534276 • Letter: 1

Question

1- write a program in C language that will prompt the user to enter 10 integers and then will print out the integers in 2 lists: a list of odd numbers and a list of even numvbers. a sample run is shown below


enter 10 integers:

1 2 3 4 5 6 7 8 9 10

even integers: 2 4 6 8 10

odd integers: 1 3 5 7 9


2- write a function in C language with prototype

int LCM (int x, int y);

the function should find the least common multipule of integers x and y.

for example, the statement ,

printf( "LCM(8,12) = %d ", LCM (8,12));

will print LCM (8,12) =24



Explanation / Answer

//Code for 1st problem

#include<stdio.h>

int main()

{

printf("Enter 10 integers: ");

int i;

int num[10];

for(i=0;i<10;i++)

scanf("%d",&num[i]);

printf(" Even integers : ");

for(i=0;i<10;i++)

{

if(num[i]%2 == 0)

printf("%d ",num[i]);

}

printf(" Odd integers : ");

for(i=0;i<10;i++)

{

if(num[i]%2 != 0)

printf("%d ",num[i]);

}

return 1;

}



//Code for 2 problem



#include<stdio.h>

int LCM (int x, int y)

{

int i;

for(i = (x>y)?x:y; i<x*y; i++)

{

if(i%x == 0 && i%y == 0)

return i;

}

return x*y;

}

int main()

{

printf( "LCM(8,12) = %d ", LCM (8,12));


}