2. WAP To do addition of two
Number but Declare One variable
Yes it is possible in 3 different way in C
and C++ programming
Use function as well as Scope Resolution
operator
Function is block we call it n number of
times
Using Scope Resolution we use global
values
3. 1 Using function
int a;
int add();
void main() {
clrscr();
printf(“nt Addition 2 Number is %d”,add()+add());
getch(); }
int add() {
printf(“nt Enter Number”);
scanf(“%d”,&a);
return a;
}
4. Description of First program
In above program declare only one
variable “a” and declare one function
add()
In printf() just calling function 2 times
for addition. In function definition
accepting values for variable a using
scanf() and return values of a
6. Description of Second program
In this program declare only one
variable “x” declare one default
function add()
Using “cin” statement accepting value
for X and scope value for same then
doing addition and print result
7. 3 Function with return value
int p;
int add();
void main() {
clrscr();
cout<<“nt Add is”<<add ()+add();
getch(); }
int add() {
cout<<“nt Enter Number”;
cin>>p;
return p;
}
8. Description of Third program
Third program is same like as first
program only variable name is P instead of
a.