Q.no program to calculate the sum of the even and odd number in 10 natural number .
In this c-basic program, we will calculate the sum of the even and odd number from 10 natural number by taking input from the user .
if a number is divisible by 2 is even number. If condition will check weather the remainder of the divisible by 2 is equal to 0 or 1.
if the remainder value is 0 then the number is even ,and the remainder value is 1 then odd number .
#include<stdio.h>
#include<conio.h>
main()
{
int a[10],i,even=0,odd=0;
printf("enter the 10 natural number");
for(i=0;i<=9;i++)
scanf("%d",&a[i]);
for(i=0;i<=9;i++)
{
if(a[i]%2==0)
even=even+a[i];
else
odd=odd+a[i];
}
printf("sum of the even number is %d",even);
printf("sum of the odd number is %d",odd);
getch();
}
output:-

No comments:
Post a Comment