"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Sunday, February 21, 2010

Write a C++ program to use following functions:

(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.

void sqlarge(int &a, int &b)
if(a >b)
   a = a*a;
   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 ;



No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.