Latest News
|
|
UNIT 2
TOPICS TO BE COVERED IN THIS UNIT:
- Designing structured programs
- Functions - basics, parameter passing
- Storage classes- extern, auto, register, static
- Scope rules and block structure
- User defined functions
- Standard Library functions
- Recursive functions
- Header files
- C preprocessor
TEACHING MATERIAL
Unit 2 Teaching Aids - Click Here
TUTORIAL MATERIAL
Tutorial 1
- Give the pictorial representation of different symbols used in flowchart and when it is used?
- Write an algorithm/ pseudo code for multiplication of three given numbers?
- Write an algorithm for given problems.
- Calculate the simple interest formula I =PNR / 100 (where P- price, N- number of years, R- Rate of Interest)
- Find out the Area and Perimeter of a circle.
- Name different sections used in structure of a 'C' program by using arrows.K
#include ---------------->
Int s = 1;------------------------------>
main()-------------------------------->
{
Int a, b;------------------------------>
Printf("enter a&b values");
Scanf("%d%d", &a, &b,&c); }--->
S=add(a, b,c);
Printf("product is %d", S);
}
add(int x, int y,int z)
{
s=a+b+c; }-------->
return(s);
}
Tutorial 2
- Indentify which one is a Reserved word, Identifier, Constants, Variables.
Height perimeter '8' 0
Avg "Hello" 10 5.52
Sum "India" x #define N 10
Area 'a' y # define a 15
Auto sizeof goto default
-
main()
{
int i = 3
printf("%d", i);
printf("%d", i++);
printf("%d", i++);
printf("%d", ++i);
printf("%d",++i);
printf("%d", i++);
}
What is the output?
- Do the following:.
- Read int x & int y values and o/p c = 2a+3b. Implement that by using scanf & Printf statement.
- (1.) Condition 3 > 2 . (2.) print True or False. Implement that using conditional operator.
- Name different types of operators?
Tutorial 3
- Write a program by using following conditions. Read input value X.
If x = 0 print output value y = 0;
If x < 1 print output value y = -1;
If x > 1 print output value y = 1;
- Read the value of age, if age>17 print eligible for voting otherwise print not eligible.
- Write a program to find the roots of quadratic equation using if - else condition?
- Write a program to find the largest of 3 numbers using nested if - else statement?
-
main()
{
Int i,j;
for(i=1;i<=10;i++)
for(j=1;j<=3;j++)
{
If (i>3)
break;
Printf("%d%d",i,j);
}
Printf("comes out of the loop");
}
What is the output?
-
main( )
{
Int x;
Printf("enter a number");
Scanf("%d",&x);
If (x%2==0)
Goto even;
Else
Goto odd;
Even:printf("no is even");
Odd :printf("no is odd");
}
Find the output when
a) x=12;
b )x=27;
Tutorial 4
- Read two values a & b. Now write a program to perform Addition, Subtraction, Multiplication and Division of two numbers using switch.
- Write a program to display 1 to 20 numbers.
- Using while loop
- Using do - while.
- Using for - loop.
-
3. Write a program to implement nth table to the given number
- Using while loop
- Using do - while.
- Using for -loop.
PRACTICE PROBLEMS
Beginner Problems
- What is the output of the following program?
int a=5;
void main()
{
int a=10;
printf("%d",a);
}
- Write a program to add two numbers by using functions.
(The function should take parameters and return a value)
- Write a c program to find factorial of a number by using recursive function.
- Write a program to find mn using library function
- Write a program to swap two numbers by using call by address.
- What is the output of the following program?
void show();
main()
{
show();
show();
show();
}
void show()
{
static int i=0;
i++;
printf("%d",i);
}
- What is the output of the following program?
main()
{
int i=9;
{
int i=8;
printf("%d",i);
}
printf("%d",i);
}
Intermediate Problems
- Write a program to find sum of given series by using function with argument and
return value. e = 2 + 3/1! - 6/2! + 9/3! - 12/4! .....!
- Write a Program to find GCD of 2 numbers using recursion.
- Write a program to generate Fibonacci numbers using recursion.
- Program to solve Towers of Hanoi problem using recursion.
- What is the output of the following program?
#include
#define a 10
main()
{
#define a 50
printf("%d",a);
}
- What is the output of the following program?
main()
{
extern out;
printf("%d", out);
}
int out=100;
- What is the output of the following program?
int a,b;
void swap(int,int);
main()
{
a=5;
b=10;
clrscr();
swap(a,b);
printf("%d %d",a,b);
}
void swap(int a, int b)
{
int t;
t=a;
a=b;
b=t;
}
Advanced Problems
- What is the output of the following program
#define mul(x) x*x
void main()
{
int m;
clrscr();
m=mul(4+3);
printf("%d" ,m);
}
- What is the output of the following program
#define square(x) x*x
main()
{
int i;
i=64/square(4);
printf("%d",i);
}
- #define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}
- What is wrong with this program.
main()
{
register int a=2;
printf("Address of a = %d",&a);
printf("Value of a = %d",a);
}
- What is the output of the following program.
#define FALSE -1
#define TRUE 1
#define NULL 0
main()
{
if(NULL)
puts("NULL");
else if(FALSE)
puts("TRUE");
else
puts("FALSE");
}
- What is the output of the following program.
main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
This Page Is Designed By Mohan Ajay Kumar
|