0% found this document useful (0 votes)
17 views10 pages

CT1 Set 2

The document outlines the Cycle Test I for the B.Tech program, focusing on Programming for Problem Solving with a maximum score of 50. It includes course learning outcomes, a series of questions divided into three parts, and key programming concepts in C, such as data types, control statements, and algorithms. Additionally, it provides sample answers and explanations for each question.

Uploaded by

nimishparmar06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views10 pages

CT1 Set 2

The document outlines the Cycle Test I for the B.Tech program, focusing on Programming for Problem Solving with a maximum score of 50. It includes course learning outcomes, a series of questions divided into three parts, and key programming concepts in C, such as data types, control statements, and algorithms. Additionally, it provides sample answers and explanations for each question.

Uploaded by

nimishparmar06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

CYCLE TEST – I Slot F , Batch 1

SET 2
Academic Year: 2022-2023 (EVEN Semester) OFF LINE

Program offered: B.Tech (All Branches) Year / Sem: I/ II


Max. Marks: 50 Time : 9.45 AM -11.30 AM
Date : 08-03-2023
Course Code and Title: 21CSS101J: Programming for Problem Solving

Course Learning Rationale (CLR):


CLR-1: Think and evolve with a logic to construct an algorithm and pseudo code that can be converted into a program.
CLR-2 : Utilize the appropriate operators and control statements to solve engineering problems
CLR-3 : Store and retrieve data in a single and multidimensional array
Course Learning Outcomes (CLO):
CLO-1: To solve problems through computer programming. Express the basic data types and variables in C
CLO-2 : To use appropriate data types in simple data processing applications. To create programs using the concept of
arrays.

Part A (10*1=10 Marks)

Sl.No Question CO PO BL Mark PI


s COD
E
1 Which of the following is true for variable names in C? 1 1 1 1 1.6.1

(a) Variable names cannot start with a digit


(b) Variable can be of any length
(c) They can contain alphanumeric characters as well as
special characters
(d) Reserved Word can be used as variable name

2 C Language was developed at ? 1 2 1 1 2.5.2

A. AT & T Bell Laboratory


B. MIT University
C. Harvard University
D. Stanford Lab
3 1 2 1 1 2.5.2

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;

while(a <= 27)


{
printf("%d ", a);
a++;
}

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

Part B (4*5Marks=20 Marks)


Answer all questions

Sl.No Question CO PO BL Marks PI


Code
11 Determine the hierarchy of operations and evaluate the 1 2 3 5 2.6.3
following expression, assuming that kk is a float variable:
kk = 3 / 2 * 4 + 3 / 8

12 Compare various data types with its format specifiers 1 2 3 5 2.6.3

13 Write about while and do while with suitable example 1 2 2 5 2.6.3

14 Define pointer in C and give suitable example 1 2 3 5 2.6.4

Part C( 2*10=20 Marks)

Sl.No Question CO PO BL Marks PI


Code
15 a. Brief about the conditional statements or decision making in 1 2 3 10 2.6.3
C
(OR)
15 b. Kannan borrowed Rs.30000 from a bank to buy a car at a rate 1 2 3 10 2.6.3
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?

16 a. Write a C program to find the average of Ten integers using 2 2 2 10 2.6.3


Array.

(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.

Compare various data types with its format specifies

Format Specifiers Type of Output

A decimal integer or signed


%d or %i
integer
%c Signed character

%f Signed float

%e A floating-point number

A string or sequence of
%s
character

%lf double

%Lf Long double

%o Octal integer

%u Short unsigned integer

%ld Long decimal integer

%x Hexadecimal integer

Print memory address in the


%p
hexadecimal form

13.
Write about while and do while with suitable example

Key Differences between while and do-while loop


 While loop checks the condition first and then executes the statement(s), whereas do while loop will execute the
statement(s) at least once, then the condition is checked.
 While loop is entry controlled loop, whereas do while is exit controlled loop.
 In the while loop, we do not need to add a semicolon at the end of a while condition, but we need to add a
semicolon at the end of the while condition in the do-while loop.
 While loop statement(s) is executed zero times if the condition is false, whereas the do-while statement is executed
at least once.
 While loop allows initialization of counter variable before starting the body of a loop, whereas do while loop
allows initialization of counter variable before and after starting the body of a loop

Example:
While:

// Print numbers from 1 to 5

#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

// Program to add numbers until the user enters zero

#include <stdio.h>
int main() {
double number, sum = 0;

// the body of the loop is executed at least once


do {
printf("Enter a number: ");
scanf("%lf", &number);
sum += number;
}
while(number != 0.0);

printf("Sum = %.2lf",sum);

return 0;
}

Result:

Enter a number: 1.5


Enter a number: 2.4
Enter a number: -3.4
Enter a number: 4.2
Enter a number: 0
Sum = 4.70

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 pointer pc: 2686784


Content of pointer pc: 22

Address of pointer pc: 2686784


Content of pointer pc: 11

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:

Compound Interest = 46826.88

16.a

Write a C program to find the average of Ten integers using Array.

#include <stdio.h>
int main() {
int n, i;
float num[100], sum = 0.0, avg;

printf("Enter the numbers of elements: ");


scanf("%d", &n);

while (n > 10 || n < 1) {


printf("Error! number should in range of (1 to 10).\n");
printf("Enter the number again: ");
scanf("%d", &n);
}

for (i = 0; i < n; ++i) {


printf("%d. Enter number: ", i + 1);
scanf("%f", &num[i]);
sum += num[i];
}

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.

Write a program to calculate the salary as per the


following table:

#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);

if(g=='m' && yos>=10 && qual==1)


sal = 15000;

else if( (g=='m' && yos>=10 && qual==0) || ( g=='m' && yos<10 && qual==1 ) )
sal = 10000;

else if( g=='m' && yos<10 && qual==0)


sal = 7000;

else if( g=='f' && yos>=10 && qual==1)


sal = 12000;

else if( g=='f' && yos>=10 && qual==0)


sal = 9000;

else if( g=='f' && yos<10 && qual==1)


sal = 10000;

else if( g=='f' && yos<10 && qual==0)


sal = 6000;

printf("Salary of Employee=%d\n" , sal);


getch();
}

Result :

Enter Gender , Years of Service and Qualification ( G=0 , PG=1 ):


f 25 1
Salary of Employee=12000

You might also like