Program to finding sum of 1 to n

0
25
#include<stdio.h>
#include<conio.h>
void main()
{
 int n,i;  
 long s=0;   /* n for given number, s for sum */
 clrscr();
 printf("\n Enter n \n");
 scanf("%d",&n);
 for(i=1;i<=n;++i)
   s=s+i;
 printf("sum of numbers from 1 to %d=%ld\n", n,s):
getch();
}
  Output:
  Enter n
  5
  sum of numbers 1 to 5=15

 

 

 

Program to finding sum of 1 to n C Program to finding sum of 1 to n finding sum of 1 to n Program to find sum of n numbersĀ Program to find sum 1 to n numbers program to find the sum of n natural numbers

LEAVE A REPLY

Please enter your comment!
Please enter your name here