Write a program in C to find the separately sum of odd and even numbers in given numbers in array.
#include<stdio.h> #include<conio.h> void main() { int a[50],i,n,even_sum=0,odd_sum=0; clrscr(); printf("Enter a number you want to insert:-"); scanf("%d",&n); printf("Enter %d numbers:-",n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) if(a[i]%2==0) even_sum=even_sum+a[i]; else odd_sum=odd_sum+a[i]; printf("even sum =%d",even_sum); printf("\nodd sum=%d",odd_sum); getch(); }Output:-
Related programs:
- Write a program in C to sort array elements in ascending order.
- Write a program in C to check that a number entered by the user is Armstrong number.
- Write a program to print 1 to 100 numbers using while loop.
- Write a program in C to find greatest prime number less than a given positive number.
0 Comments