Problem 33

author
By Supreme2023-03-15
Problem Statement :
Write a program to find out which number is even or odd from list of 10 numbers using array
Code:

#include <stdio.h>

int main(){

//33. Write a program to find out which number is even or odd from list of //10 numbers usingarray

printf("\tEven/Odd");
printf("\n======================================\n\n");
int num[10],i,j,k;

for(i=0;i<10;i++){
printf("Enter The Number [%d] : ",i+1);
scanf("%d",&num[i]);
}

printf("\n\n--------------------------------------\n\n");

for(j=0;j<10;j++){
if((num[j]%2)==0){
printf("%d ",num[j]);
}
}
printf("Are Even Numbers\n\n");

for(k=0;k<10;k++){
if((num[k]%2)!=0){
printf("%d ",num[k]);
}
}
printf("Are Odd Numbers\n\n");

return 0;
}

Description :
  • This program helps to identify even and odd numbers from a list of 10 numbers using arrays.
  • The program starts by printing a message to the user to input 10 numbers.
  • An integer array called "num" of size 10 is declared to store the input numbers.
  • Using a for loop, the program prompts the user to enter the 10 numbers and stores them in the array "num".
  • After the numbers are entered, the program prints a separator line and then loops through the "num" array to identify even and odd numbers.
  • If the number at the current index in the "num" array is divisible by 2 (i.e., the remainder of the division is 0), it is identified as an even number and printed to the console.
  • Similarly, if the number at the current index in the "num" array is not divisible by 2 (i.e., the remainder of the division is not 0), it is identified as an odd number and printed to the console.
  • The program ends by returning 0.
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.