Thursday, March 8, 2012

Program to print first n natural no and their sum

//Program to print first n natural no and their sum.
#include<stdio.h>
#include<conio.h>
main()
{
      int i,sum,n;
      printf("How many natural no?");
      scanf("%d",&n);
      sum=0;
      for(i=1;i<=n;i++)
      {  printf("%d\n",i);
         sum=sum+i;
      }
      printf("The sum of first %d natural no is :-%d",i,sum);
      getch();
      }

No comments:

Post a Comment