n terms of natural

Run Settings
LanguageC
Language Version
Run Command
/*Exercise-4: a) write a program in C to display the n terms of even natural number and their sum. */ #include <stdio.h> void main() { int i,n,sum=0; printf("Input number of terms : "); scanf("%d",&n); printf("\nThe even numbers are :"); for(i=1;i<=n;i++) { printf("%d ",2*i); sum+=2*i; } printf("\nThe Sum of even Natural Number upto %d terms : %d \n",n,sum); }
Editor Settings
Theme
Key bindings
Full width
Lines