Friday, 4 November 2016

Q. 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);
  }

No comments:

Post a Comment

Basic Implementation of Array as a Pointer

#include<iostream.h> #include<conio.h> void main() { clrscr();   int arr[5];   cout<<"Enter 5 nos. ";   f...