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

Write a c program to find sum of even and odd numbers

Write a c program to find sum of even and odd numbers

#include<stdio.h>

#include<conio.h>

void main()

{

int i,n,osum=0,esum=0;

clrscr();

printf("Enter the number: ");

scanf("%d",&n);

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

{

         if(i%2==0)

                  esum=esum+i;

         else

                  osum=osum+i;

}

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

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

getch();

}

Output:

Enter the number: 10

Sum of all even numbers=30                                                     

Sum of all odd numbers=25          


Write a c program to find sum of even and odd numbers Write a c program to find sum of even and odd numbers Reviewed by Vision Academy on December 18, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.