google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a program to compute sum of even and odd numbers - 2nd puc computer science

Write a program to compute sum of even and odd numbers

Write a program to compute sum of even and odd numbers

#include<stdio.h>

#include<conio.h>

void main()

{

int a[20],i,evensum=0,oddsum=0,n;

clrscr();

printf("How many elements? ");

scanf("%d",&n);

printf("Enter the elements\n");

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

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

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

{

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

         evensum+=a[i];

         else

         oddsum+=a[i];

}

printf("Sum of even numbers=%d\n",evensum);

printf("Sum of odd numbers=%d",oddsum);

getch();

}

Output:

How many elements? 3

Enter the elements                                                             

1                                                                              

2                                                                              

3                                                                              

Sum of even numbers=2                                                          

Sum of odd numbers=4
Write a program to compute sum of even and odd numbers Write a program to compute sum of even and odd numbers Reviewed by Vision Academy on December 12, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.