Thursday, August 19, 2010

C Programming - calculate sum of range of number

#include<stdio.h>
#include<conio.h>
main()
{
int r1,r2,i,sum=0;
clrscr();
printf("\n enter the range of number=");
scanf("\n %d%d",&r1,&r2);
for(i=r1;i<=r2;i++)
{
sum=sum+i;
}
printf("\n sum of range of number=%d",sum);
getch();
}



Output:-
Enter the range of number=1
10
Sum of range of number=55;

No comments:

Post a Comment