Download - Ex2

Transcript
Page 1: Ex2

What output does the following program produce when executed?Use the right half of this page. Draw a box around your final answer.#include <iostream>using namespace std;int x = 49;void g(int y){static int x = 7;x += y;cout << x << ’\n’;}void f(int a, int b){g(-1);switch(a) {case 3:case 4:cout << ’*’ << x << ’\n’;x = a = b = 19;break;case 1:case 2:cout << ’&’ << x << ’\n’;x = a = b = 41;break;default:cout << ’?’ << x << ’\n’;break;}}int main(void){int a=1, b=2, x=b-a;g(3);f(x, b);cout << a << ’\n’ << b << ’\n’ << x << ’\n’;return(0);}

Page 2: Ex2

Write a function " Perfect " that will indicate whether or not a number given to it is a perfect number or not .Hint : An integer number is said to be a perfect number if the sum of its factors, including 1 (but not the number itself), is equal to the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3..


Top Related