(i) sqlarge() that is passed two int arguments by reference and then sets the larger of the two numbers to its square.
(ii) sum() that is passed an int argument by value and that returns the sum of the individual digits of the passed number.
(iii) main() that exercises above two functions by getting two integers from the user and by printing the sum of the individual digits of the square of the larger number.
{
if(a >b)
a = a*a;
else
b = b*b;
}
int sum(int x);
{
int r, s=0;
while(x > 0)
{
r = x % 10;
s = s+r;
x = x / 10;
}
return s;
}
void main()
{
int num1, num2;
cout<<" \ n Enter a number :";
int tot = sum(num1);
cout<< " \n THE SUM OF DIGITS = " << tot;
cout << "\n Enter another number : ";
cin>> num2;
cout<< "\n The two numbers originally are " << num1 << " and " << num2 ;
sqlarge(num1, num2);
cout<< "\n The two numbers after change are " << num1 << " and " << num2 ;
getch();
}
(ii) sum() that is passed an int argument by value and that returns the sum of the individual digits of the passed number.
(iii) main() that exercises above two functions by getting two integers from the user and by printing the sum of the individual digits of the square of the larger number.
#include <iostream.h>
#include <conio.h>
void sqlarge(int &a, int &b){
if(a >b)
a = a*a;
else
b = b*b;
}
int sum(int x);
{
int r, s=0;
while(x > 0)
{
r = x % 10;
s = s+r;
x = x / 10;
}
return s;
}
void main()
{
int num1, num2;
cout<<" \ n Enter a number :";
int tot = sum(num1);
cout<< " \n THE SUM OF DIGITS = " << tot;
cout << "\n Enter another number : ";
cin>> num2;
cout<< "\n The two numbers originally are " << num1 << " and " << num2 ;
sqlarge(num1, num2);
cout<< "\n The two numbers after change are " << num1 << " and " << num2 ;
getch();
}
No comments:
Post a Comment