Sum up to given number.
A program for find the sum upto the number entered by the user:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int y,t,sum=0;
printf("Enter the last value of the series, up to where the sum is required: ");
scanf("%d",&t);
for(y=1;y<=t;y++)
{
sum=sum+y;
}
printf("Sum of the series is: %f",sum);
getch();
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int y,t,sum=0;
printf("Enter the last value of the series, up to where the sum is required: ");
scanf("%d",&t);
for(y=1;y<=t;y++)
{
sum=sum+y;
}
printf("Sum of the series is: %f",sum);
getch();
getch();
}
Comments
Post a Comment