Write a program to find the sum of number from 1 to n

//this is a program to find the sum of number from 1 to n
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
unsigned long int sum=0;


printf("\n\nEnter any number: ");
scanf("%d",&n);

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

printf("\n\nSum = %d",sum);

getch();
}

Previous
Next Post »