CT1 Set 2
CT1 Set 2
SET 2
Academic Year: 2022-2023 (EVEN Semester) OFF LINE
A) 0
B) 1
C) 10
D) 14
4 Which is correct with respect to size of the data types? 1 2 1 1 2.5.2
a) char > int > float
b) int > char > float
c) char < int < double
d) double > char > int
5 What will be the output of the following C code? 1 2 1 1 2.5.
2
#include <stdio.h>
int main()
{
int i = 0;
int x = i++, y = ++i;
printf("%d % d\n", x, y);
return 0;
}
a) 0, 2
b) 0, 1
c) 1, 2
d) Undefined
6 Choose a syntax for C Ternary Operator from the list. 2 2 1 1 2.5.
A) condition ? expression1 : expression2 2
B) condition : expression1 ? expression2
C) condition ? expression1 < expression2
D) condition < expression1 ? expression2
7 What is the output of C Program.? 2 2 1 1 2.5.
2
int main()
{
int a=0;
a = printf("4");
printf("%d",a);
return 0;
}
A) 04
B) compiler error
C) 40
D) 41
8 What is the output of C Program.? 2 2 2 1 2.5.
int main() 2
{
if( 10 > 9 )
printf("Singapore\n");
else if(4%2 == 0)
printf("England\n");
printf("Poland");
return 0;
}
A) Singapore
B) Singapore
Poland
C) Singapore
England
Poland
D) England
Poland
9 What is the output of C Program.? 2 2 2 1 2.5.
2
int main()
{
int a=25;
return 0;
}
A) 25 25 25
B) 25 26 27
C) 27 27 27
D) Compiler error
10 The keyword ‘break’ cannot be simply used within ______. 2 2 2 1 2.5.2
a) do-while
b) if-else
c) for
d) while
(OR)
16 b. Write a program to calculate the salary as per the 2 2 2 10 2.6.3
following table:
KEY
Part A
1.a
2.a
3.c
4.c
5.a
6.a
7.d
8.b
9.b
10.b
Part B
11.
Determine the hierarchy of operations and evaluate the
following expression, assuming that kk is a float variable:
kk = 3 / 2 * 4 + 3 / 8
kk = 3 / 2 * 4 + 3 / 8
Stepwise evaluation of this expression is shown below:
kk = 3 / 2 * 4 + 3 / 8
kk = 1 * 4 + 3 / 8 operation: /
kk = 4 + 3 / 8 +operation: *
kk = 4 + 0 operation: /
kk = 4 operation: +
12.
%f Signed float
%e A floating-point number
A string or sequence of
%s
character
%lf double
%o Octal integer
%x Hexadecimal integer
13.
Write about while and do while with suitable example
Example:
While:
#include <stdio.h>
int main() {
int i = 1;
while (i <= 5) {
printf("%d\n", i);
++i;
}
return 0;
}
Result:
1
2
3
4
5
do - While
#include <stdio.h>
int main() {
double number, sum = 0;
printf("Sum = %.2lf",sum);
return 0;
}
Result:
14.
Define pointer in C and give suitable example
Pointer:
The Pointer in C, is a variable that stores address of another variable. A pointer can also be used to refer to another pointer
function. A pointer can be incremented/decremented, i.e., to point to the next/ previous memory location. The purpose of
pointer is to save memory space and achieve faster execution time.
#include <stdio.h>
int main()
{
int* pc, c;
c = 22;
printf("Address of c: %p\n", &c);
printf("Value of c: %d\n\n", c); // 22
pc = &c;
printf("Address of pointer pc: %p\n", pc);
printf("Content of pointer pc: %d\n\n", *pc); // 22
c = 11;
printf("Address of pointer pc: %p\n", pc);
printf("Content of pointer pc: %d\n\n", *pc); // 11
*pc = 2;
printf("Address of c: %p\n", &c);
printf("Value of c: %d\n\n", c); // 2
return 0;
}
Result:
Address of c: 2686784
Value of c: 22
Address of c: 2686784
Value of c: 2
Part C
15.a
Brief about the conditional statements or decision making in C
1. if statement
2. if-else statements
3. nested if statements
4. if-else-if ladder
5. switch statements
6. Jump Statements:
break
continue
goto
return
15.b
Kannan borrowed Rs.30000 from a bank to buy a car at a rate of 16% p.a., compounded yearly. What amount will she
pay at the end of 3 years to clear the loan? Therefore, could you help her to pay the correct amount by writing
Algorithm, Flowchart and C program to find the solution?
Algorithm:
Step 1: start
Step 2: collect the inputs for principle, rate, time
Step3:clacuateCI=principle*(pow((1+rate/100),time)) Step 4: Display CI
Step 5: Stop
Flowchart:
Program:
#include<stdio.h>
#include<math.h>
int main()
{
float principle,rate,time,CI;
principle=30000;
time=3;
rate=16;
CI=principle*(pow((1+rate/100),time));
printf("Compound Interest = %.2f\n", CI);
return 0;
}
Result:
16.a
#include <stdio.h>
int main() {
int n, i;
float num[100], sum = 0.0, avg;
avg = sum / n;
printf("Average = %.2f", avg);
return 0;
}
Result:
Enter the numbers of elements: 10
1. Enter number: 1
2. Enter number: 2
3. Enter number: 3
4. Enter number: 4
5. Enter number: 5
6. Enter number: 6
7. Enter number: 7
8. Enter number: 8
9. Enter number: 9
10. Enter number: 10
Average = 5.50
16.
#include<stdio.h>
#include<conio.h>
void main()
{
char g;
int yos , qual , sal=0;
clrscr();
printf(" Enter Gender , Years of Service and Qualification ( G=0 , PG=1 ):");
/* G stands for Graduate and PG stands for Post-Graduate */
scanf("%c%d%d" , &g , &yos , &qual);
else if( (g=='m' && yos>=10 && qual==0) || ( g=='m' && yos<10 && qual==1 ) )
sal = 10000;
Result :