WAF TO FIND SUM OF OF DIGITS IN A GIVEN RANGE

#include<iostream.h>
#include<conio.h>
float sum_of_digits(float a,float b);
void main()
{
clrscr();
int w,x,y;
cout<<“Enter the range below “<<“\n”;
cout<<“From (included) “;
cin>>w;
cout<<“To (included) “;
cin>>x;
y=sum_of_digits(w,x);
cout<<“Sum of digits from “<<w<<” to “<<x<<” is “<<y;
getch();
}
float sum_of_digits(float a,float b)
{
int sum=0;
for (int i=a;i<=b;i++)
{ sum=sum+i;
}
return(sum);
}

Comments

Popular Posts