Write a C program to find the sum of numbers in a given range
Program:-
#include<stdio.h>
int main()
{
int start, end;
scanf(“%d”,&start);
scanf(“%d”,&end);
int i, sum = 0;
for(i = start; i <= end; i++)
{
sum = sum + i;
}
printf(“%d”,sum);
return 0;
}
int main()
{
int start, end;
scanf(“%d”,&start);
scanf(“%d”,&end);
int i, sum = 0;
for(i = start; i <= end; i++)
{
sum = sum + i;
}
printf(“%d”,sum);
return 0;
}
Output:-
....
0 comments:
Post a Comment