Pages

Showing posts with label their. Show all posts
Showing posts with label their. Show all posts

Saturday, February 14, 2015

C program to print first n natural numbers and their sum


#include<stdio.h>
#include<conio.h>

void main()
{
int n,i,sum=0;
clrscr(); //to clear the screen
printf("Enter the value of n:");
scanf("%d",&n);

for(i=1;i<=n;++i)
{
printf("
%d",i);

sum+=i;
}
printf("

Sum of first n natural numbers is:%d",sum);

getch(); //to stop the screen
}
Read more »