Assignment of Output and Series Questions
Assignment of Output and Series Questions
5. Give output:
#include<iostream.h>
int global = 20;
void fun (int &x, int y)
{
x = x – y; y = x * 10;
cout << x << ‘, ’ << y << ‘\n’;
}
void main()
{
int global = 8;
fun (:: global, global);
cout << global << ‘, ’ << :: global << ‘\n’;
fun (global, :: global);
cout << global << ‘, ’ << :: global << ‘\n’;
}
6. Give output:
#include<iostream.h>
int fun ( int &a, int b = 0)
{
if (a % b = = 0) return ++ a;
else return b - - ;
}
void main()
{
int x = 20, y = 23;
y = fun (x, y);
cout << x << ‘, ’ << y << ‘\n’;
x = fun (y);
cout << x << ‘, ’ << y << ‘\n’;
y = fun (x);
cout << x << ‘, ’ << y << ‘\n’;
}
7. Find output
#include<iostream.h>
void fun (int &A, int &B)
{
A = A + B;
B = A – B;
A = A – B;
}
void main ( )
{
int a = 4, b = 18;
fun (a, b);
cout << a << “, ” << b;
}
8. Give output:
void Change (int x[4]. int i)
{
x[i] = x[i] * I;
}
void main ( )
{
int x[ ] = {11, 21, 31, 41};
for (int i = 0; i < 4; i++)
{
Change (x, i);
cout << x[i] << ‘\n’;
}
}
8. In the following program, if the value of N given by the user is 20, what maximum and
minimum value the program could possibly display ()?
#include<iostream.h>
#include<stdlib.h>
void main()
{
int N, Guessme;
randomize();
cin>>N;
Guessme = random(N-10) + 10 ;
cout<<Guessme<<endl;
}
9. Rewrite the following program after removing the error(s), if any. Underline each
correction.
#include <iostream.h>
void main()
{
int x, sum =0;
cin>>n;
for (x=1;x<100, x+=2)
if x%2=0
sum+=x;
cout<< “sum=” >>sum;
}
17 Give output
int Execute( int M)
{
if (M % 3 = 0)
return M * 3;
else
return M + 10;
}
void output( int B = 2)
{
for (int T = 0; T < B; T++)
cout << Execute(T) << “*”;
cout << endl;
}
void main()
{
output (4);
output ( );
output (3);
}
25 Write a C++ function SUMFUN() having parameters X (of type double) and n (of
type integer)
with a result type as double to find the sum of the series given below :
X + X2/3! + X3/5! + ………….+ Xn/(2N-1)!