C Program to Print Sum of n Natural Numbers Term Odd Natural Numbers Even Natural Number

C Program to Print Sum of n Natural Numbers Term Odd Natural Numbers Even Natural Number

Write a C program to print the sum of n natural numbers, the sum of n term odd natural numbers, and the sum of n terms even natural numbers.


#include 
void main()
{
 int i,n,sum=0,j,su=0,k,s=0;
 printf("Input Value of terms : ");
 scanf("%d",&n);
 printf("
The first %d natural numbers are:
",n);
 for(i=1;i<=n;i++)
 {
 printf("%d ",i);
 sum+=i;
 }
 printf("
The Sum of natural numbers upto %d terms : %d 
",n,sum);
 printf("
The odd numbers are :");
 for(j=1;j<=n;j++)
 {
 printf("%d ",2*j-1);
 su+=2*j-1;
 }
 printf("
The Sum of odd Natural Number upto %d terms : %d 
",n,su);
 printf("
The even numbers are :");
 for(k=1;k<=n;k++)
 {
 printf("%d ",2*k);
 s+=2*k;
 }
 printf("
The Sum of even Natural Number upto %d terms : %d 
",n,s);
}