Starting Vocational Training From 1-May-2024 Get Detail


Write a program in C to display the n terms of even natural number and their sum. 
Test Data :
Input number of terms : 5 
Expected Output : 
The even numbers are :2 4 6 8 10 
The Sum of even Natural Number upto 5 terms : 30


???????


#include <stdio.h>

void main()
{
   int i,n,sum=0;

   printf("Input number of terms : ");
   scanf("%d",&n);
   printf(" The even numbers are :");
   for(i=1;i<=n;i++)
   {
     printf("%d ",2*i);
     sum+=2*i;
   }
   printf(" The Sum of even Natural Number upto %d terms : %d ",n,sum);