You are on page 1of 8

Q: W.A.P to add three numbers using function with no argument and no return type?

Sol:
#include<iostream.h>
#include<conio.h>
void main ( )
{
int a , b , c , s ;
void sum ( )
clrscr ( );
sum ( );
getch ( );
}
void sum ( )
{
cout<<” Enter three numbers “ ;
cin>>a>>b>>c;
s=a+b+c;
cout<<” \n The sum of three numbers is “ << s;
}
OUTPUT

Enter three numbers 3 4 5


The sum of three numbers is 12
Q: W.A.P to illustrate local variables?
Sol:
#include<iostream.h.>
#include<conio.h>
void main ( )
{
void fun ( );
void run ( );
int a = 10;
clrscr ( );
run ( ) ;
fun ( ) ;
cout<<” \n a = “<< a ;
getch ( ) ;
}
void fun ( )
{
int a = 20 ;
cout<<” \n a = “<< a ;
}
void run ( ) ;
{
int a = 30 ;
cout << “ \n a = “ << a;
}
OUTPUT

a = 30
a = 20
a = 10
Q. WAP to Illustrate Global Variables?
Sol.
# include <iostream.h>
#include <conio.h>
int i = 0 ;
void main ( )
{
void test ( );
void demo ( );
clrscr ( );
cout <<” i = “<<i<<”\n”;
test ( );
demo ( );
getch ( );
}
void test ( )
{
i = i + 10;
cout <<” i = “<<i<<”\n”;
}
void demo( )
{
i = i – 5;
cout <<” i = “<<i;
}
OUTPUT

i=0
i = 10
i=5
Q. 4. WAP to find the cube of a given number by passing argument and return type?
Sol.
#include <iostream.h>
#include <conio.h>
void main ( )
{
int cube (int);
int n;
clrscr ( );
cout <<“Enter the number”;
cin >> n;
cube (n);
getch ( );
}
int cube (int x)
{
int y;
y = x * x * x;
cout <<”\n cube is “<<y;
}
OUTPUT

Enter the number 3


cube is 27

You might also like