Note =
-Draw stackframe for each question in your notebook.
-Do not write question in notebook,just stackframe and correct question number.
-Write output neet and clean after stackframe.
-Once you finish with all the questions,check these code outputs using dev-cpp.
-Understanding memory and execution is the main motto.Don't just focus on correct
output.
1)
#include<stdio.h>
void myfun();
int x = 10;
int main()
{
int x = 5;
myfun();
printf("in main x = %d",x);
return 0;
}
void myfun()
{
x = x + 8 ;
}
2)
#include<stdio.h>
void myfun();
int x = 10;
int main()
{
myfun();
myfun();
printf("in main x = %d",x);
return 0;
}
void myfun()
{
int x = 6;
x = x + 3 ;
}
3)
#include<stdio.h>
void myfun();
int x = 10;
int y = 5;
int main()
{
int x = 15;
myfun();
x = 20;
myfun();
return 0;
}
void myfun()
{
x++;
y++;
printf("\nx = %d y = %d",x,y);
}
4)
#include<stdio.h>
void myfun();
int main()
{
myfun();
myfun();
myfun();
return 0;
}
void myfun()
{
int x = 5;
int y = 10;
x++;
y++;
printf("\nx = %d y = %d",x,y);
}
5)
#include<stdio.h>
void myfun();
int main()
{
myfun();
myfun();
myfun();
return 0;
}
void myfun()
{
int x = 5;
static int y = 10;
x++;
y++;
printf("\nx = %d y = %d",x,y);
}
6)
#include<stdio.h>
void myfun();
int main()
{
myfun();
myfun();
myfun();
return 0;
}
void myfun()
{
static int y = 10;
y = 6;
y++;
printf("\ny = %d",y);
}
7)
#include<stdio.h>
void myfun();
void yourfun();
int main()
{
myfun();
myfun();
return 0;
}
void myfun()
{
int x = 5;
x++;
yourfun();
printf("\nIn myfun() x = %d",x);
}
void yourfun()
{
printf("\nIn yourfun");
}
8)
#include<stdio.h>
void myfun();
void yourfun();
int main()
{
myfun();
myfun();
return 0;
}
void myfun()
{
yourfun();
}
void yourfun()
{
static int x = 5;
x++;
printf("\nIn yourfun x = %d",x);
}
9)
#include<stdio.h>
void myfun();
void yourfun();
int x;
int main()
{
myfun();
return 0;
}
void myfun()
{
yourfun();
yourfun();
}
void yourfun()
{
x++;
printf("\nIn yourfun x = %d",x);
}
===================================================================================
============
Q2 = Trace the output of following programs and draw stackframe for each one in
notebook.
First find answer in notebook by executing with stackframe.
Then try it in machine and compare your output with machine output.
If outputs are different,find out your mistake in notebook execution.
1)#include<stdio.h>
void myfun();
void yourfun(int y);
int main()
{
myfun();
myfun();
return 0;
}
void myfun()
{
static int x = 5;
x++;
yourfun(x);
}
void yourfun(int y)
{
y++;
printf("\ny = %d",y);
}
------------------------------------------
2)
#include<stdio.h>
void myfun();
void yourfun(int y);
int main()
{
myfun();
return 0;
}
void myfun()
{
static int x = 5;
x++;
yourfun(x);
x++;
yourfun(x);
}
void yourfun(int y)
{
y++;
printf("\ny = %d",y);
}
------------------------------------------
3)
void myfun();
int main()
{
myfun(1);
return 0;
}
void myfun(int x)
{
int x;
x++;
printf("x = %d",x);
}
------------------------------------------
4)
#include<stdio.h>
void myfun();
void yourfun(int y);
int main()
{
myfun(1);
return 0;
}
void myfun(int x)
{
x++;
printf("x = %d",x);
yourfun(x+2);
}
void yourfun(int y)
{
printf("\ny = %d",y);
}
------------------------------------------
5)
void myfun();
int g = 2;
int main()
{
myfun(g);
printf("\nAfter function call g = %d",g);
return 0;
}
void myfun(int x)
{
x = x + 5;
}
------------------------------------------
6)
void myfun();
void yourfun();
int g = 2;
int main()
{
myfun();
printf("\nIn main() g = %d",g);
return 0;
}
void myfun()
{
yourfun();
yourfun();
}
void yourfun()
{
g++;
}
------------------------------------------
7)
int myfun();
int main()
{
int a;
a = myfun();
printf("\na = %d",a);
}
int myfun()
{
return 2+5;
}
------------------------------------------
8)
int myfun();
int main()
{
int a;
a = myfun(5);
a = myfun(a+2);
printf("\na = %d",a);
}
int myfun(int x)
{
return x+1;
}
------------------------------------------
9)
#include<stdio.h>
int myfun();
int yourfun();
int main()
{
int a;
a = myfun();
printf("\na = %d",a);
}
int myfun()
{
int b;
b = yourfun();
return b;
}
int yourfun()
{
return 10;
}
------------------------------------------
10)
#include<stdio.h>
int myfun();
int yourfun();
int main()
{
int a;
printf("\nSquare of 4 = %d",myfun(4));
}
int myfun(int x)
{
int b;
b = x*x;
return b;
}
==============================================
Q3.Write programs for following questions.
1.Scan a number from user.Check if it is prime or not.
2.Scan 2 integers from user.Find their LCM and GCD.
3.Scan a number from user.Find addition of all digits in a number.
4.Scan a number from user.Check if it is pallindrome or not.
5.Print following patterns using for loop.
1.
ABCDE
ABCD
ABC
AB
A
------------
2.
----A
---AB
--ABC
-ABCD
ABCDE
-----------
3.
12345
-1234
--123
---12
----1
6.Print following patterns using while loop
1.
12345
1234
123
12
1
2.
1
12
123
1234
12345
7.Write a menu driven program for 4 arithmetic operations of 2 integers.
8.Scan an integer in main().Define function square() and cube() to find its square
and cube.
9.Write a program to scan 2 itegers in main().Define function division() and
multiplication
to find their division and multiplication.Pint both results back in main().
10.WAP to explain static variable.