0% found this document useful (0 votes)
191 views

User Defined Function Assignment

This document contains 9 questions about writing and calling functions in C++. The questions cover topics like: - Writing functions to return the sum and factorial of integers - Writing a function to find and print prime numbers between two given numbers - Writing a function to calculate powers of a number with optional arguments - Writing a function that passes arguments by reference and modifies them - Analyzing and predicting the output of programs that call functions passing arguments by value and reference

Uploaded by

deemalhotra73
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views

User Defined Function Assignment

This document contains 9 questions about writing and calling functions in C++. The questions cover topics like: - Writing functions to return the sum and factorial of integers - Writing a function to find and print prime numbers between two given numbers - Writing a function to calculate powers of a number with optional arguments - Writing a function that passes arguments by reference and modifies them - Analyzing and predicting the output of programs that call functions passing arguments by value and reference

Uploaded by

deemalhotra73
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

USER DEFINED FUNCTION

[SET 1]
Question 1

Write a program using function which accept two integers as an argument and
return its sum. Call this function from main( ) and print the results in main( ).

Question 2

Write a function to calculate the factorial value of any integer as an argument.


Call this function from main( ) and print the results in main( ).

Question 3

Write a function that receives two numbers as an argument and display all prime
numbers between these two numbers. Call this function from main( ).

Question 4

Raising a number to a power p is the same as multiplying n by itself p times.


Write a function called power that takes two arguments, a double value for n and
an int value for p, and return the result as double value. Use default argument of
2 for p, so that if this argument is omitted the number will be squared. Write the
main function that gets value from the user to test power function.

Question 5

Write a function called zero_small() that has two integer arguments being passed
by reference and sets the smaller of the two numbers to 0. Write the main
program to access the function.

Question 6

Write the output of the following program :


#include <iostream.h>
void X(int &A, int &B)
{
A = A + B;
B = A - B;
A=A-B;
}
void main()
{
int a = 4, b =18;
X(a,b);
cout<<a<<,<<b;
}

Question 7

Write the output of the following program:


#include <iostream.h>
void X(int A, int &B)
{
A = A+B;
B = A-B;
A = A-B;

}
void main()
{
int a=4, b=l8;
X(a,b);
cout<< a <<,<<b;
}
Question 8

Write the output of the following program:


# include <iostream.h>
void Execute(int &B, int C=100)
{
int TEMP = B + C;
B += TEMP;
if (C == 100)
cout<<TEMP<<" "<<B<<" "<<C<<endl;
}
void main()
{
int M= 90, N = 10;
Execute(M);
cout << M << << N << endl;
Execute(M,N);
cout << M<< "<<N<< endl;
}

Question 9

Give the output of the following program


# include <iostream.h>
int global = 10;
void func(int &x, int y)
{
x = x - y;
y = x * 10;
cout << x << << y << '\n';
}
void main()
{
int global = 7:
func (::global, global);
cout << global <<, << ::global <<\n;
func(global,:: global);
cout<< global << ,<<::global<<\n;
}

You might also like