Thursday, February 17, 2011

program for display sum of all natural number from 1 to n in turbo c

#include<stdio.h>
#include<conio.h>
void main()
 {
 clrscr();
 int i,n,tot=0;
 printf("Enter any limit :-");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
  {
  tot=tot+i;
  }
 printf("Sum is => %d",tot);
 getch();
 }

No comments: