Friday, 4 November 2016

Wap to find sum 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);
  }

No comments:

Post a Comment