Thursday

Write a C program to display the sum of ‘n’ terms of even numbers

#include<stdio.h>
#include<conio.h>
void main()
  {
    int i,n,s=0,a=2;
    clrscr();
    printf("\nEnter how many numbers? ");
    scanf("%d",&n);
    for(i=0;i<n;i++)
     {
       s+=a;
       a=a+2;
     }
    printf("\n Sum of %d terms of even numbers is %d",n,s);
  getch();
  }

No comments:

Post a Comment

Rahul-Notes