Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Friday, August 12, 2022

C program to display the n terms of natural number and their sum

 C program to display the n terms of natural number and their sum



#include <stdio.h>

#include<conio.h>

main()

{

   int i,n,sum=0;

   printf("Enter how many terms : ");

   scanf("%d",&n);

   printf("\nThe first %d natural numbers are:\n",n);

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

   {

     printf("%d ",i);

     sum+=i;

   }

   printf("\nThe Sum of natural numbers upto %d terms : %d \n",n,sum);

getch();

}

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages