https://youtu.be/MWcFVMbmoiQ

Program to find the sum of Natural Numbers

Program to find the sum of Natural Numbers

/*     Sum Of Natural No.s
  */


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

   void main ()

   {  int i,sum=0,n;
       clrscr();

       printf("Pls enter the Value of Natural No. for which sum u want\n");
       scanf("%d",&n);

       for(i=1;i<=n;i++)
       {

	   if(i<=n-1)
	    {
	      printf(" %d+",i);
	  }
	  else
	  {
	   printf(" %d",i);
	  }

	     sum=sum+i;
       }

       printf("\n The sum of First %d Natural No. is %d",n,sum);
       printf("\n\n **** Please Press Any Key To Exit****");
       getch();

   }

Output

Sum-of-natural-numbers 




Facebook Likes

Youtube