#include<stdio.h>
#include<conio.h>
void main()
{
int i,a,sum=0;
printf("Enter the last integer:");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
sum=sum + i;
}
printf("The sum of integers from 1 to %d is %d",a,sum);
getch();
}
           
#include<conio.h>
void main()
{
int i,a,sum=0;
printf("Enter the last integer:");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
sum=sum + i;
}
printf("The sum of integers from 1 to %d is %d",a,sum);
getch();
}
|  | |
| Program to find sum of integers from 1 to n | 
|  | 
| Output for sum of integers from 1 to n | 

 
No comments:
Post a Comment