CIMP -Day 1
CIMP -Day 1
1. Write algorithm, flow chart and program to find the area of a circle.
Answer:
Algorithm findcirclearea
Begin
Declare the r as integer
Declare the pi=3.14,area as float
Print”Enter the value of r”
Read the value of r;
Calculate area=pi*r*r
Print the value of area
End
// Draw the flowchart
int main() {
// Write C code here
int radius;
float pi=3.14,area;
printf("Enter the radius value");
scanf("%d",&radius);
area=pi*radius*radius;
printf("The area =%f",area);
1|Page
return 0;
}
Enter the radius value5
The area =78.500000
2|Page
5. List the tokens in C, and explain in detail about them.
Answer:
3|Page
}
//If Else
if (condition) {
// stmt 1;
} else {
// stmt 2;
}
//Nested If - else
if (condition1) {
// stmt 1;
} else if (condition2) {
//stmt 2;
} else {
// stmt 3;
}
switch (expression) {
case case1:
// stmt 1;
break;
case case2:
// stmt 2;
break;
// More cases...
default:
// wrong case
}
7. What is the general structure of `C' program and explain with
example?
Answer:
//pre-processor directives
// global variables
#include<stdio.h>
Void main()
{
//data types and variable declarations
Int a,b,c;
Function();//function calls
//Statements;
}
4|Page
Function()
{
//local variables
//statements
//return statements
}
5|Page
Answer:
Operator name Operator symbol
Arithmetic +, -, *, /, %
Relational <, <=, >, >=, ==, !=
Logical &&, ||, !
Assignment =
Bitwise & , |, !
Conditional ?:
Size of Sizeof();
7|Page
16.What is recursion and write its advantages.
Answer: Recursion
The function call by its self
The function call contains the base condition till it satisfies the
function executes
Advantages
It breaks the program into smaller programs
Complexity is reduced
Problems can be solved like Fibonacci, binary search, GCD, factorial
and others
17.
18.Review the arrays and how is different from structures
Answer:
Arrays Structures
Array is a collection of similar data
Structures is a collection of
types values with same name different data types
Int a[10]; Struct student
Array stores the values sequentially{
a[0],a[1],a[2] --- a[n-1] Int ID;
Char name[10];
Char gender;
Char address[10];
Int m1,m2,m3;
Flaot avg;
} s1,s2;
Contiguous memory allocation for Members may have different data
elements of the same data type. types, and memory is allocated
separately for each member.
8|Page