0% found this document useful (0 votes)
10 views8 pages

# Include Int Main (Int X 3, y 0 (X & Y) ? Printf ("True ") : Printf ("False ") (X && Y) ? Printf ("True ") : Printf ("False ") Return 0 )

The document outlines the solution and marking scheme for the Odd Semester End Term Examination for B.Tech students in the Department of First Year. It includes various programming questions related to C language, flowcharts, algorithms, and explanations of concepts like NULL pointers and function parameter passing. Each question is accompanied by a solution and marks distribution.

Uploaded by

nevaidhyasingh
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)
10 views8 pages

# Include Int Main (Int X 3, y 0 (X & Y) ? Printf ("True ") : Printf ("False ") (X && Y) ? Printf ("True ") : Printf ("False ") Return 0 )

The document outlines the solution and marking scheme for the Odd Semester End Term Examination for B.Tech students in the Department of First Year. It includes various programming questions related to C language, flowcharts, algorithms, and explanations of concepts like NULL pointers and function parameter passing. Each question is accompanied by a solution and marks distribution.

Uploaded by

nevaidhyasingh
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/ 8

Name:

Enrolment No:

Odd Semester End Term Examination, December 2023


Department of First Year
B.Tech – All Branches
Course Code: CS1002 Course: Problem Solving Using Computers Semester: I
Time: 03 hrs. Max. Marks: 80
Solution cum Marking Scheme
SECTION A
S.No. Marks CO
Q A1 Predict the output of the following program:
# include <stdio.h>
int main()
{
int x = 3, y = 0;
2
(x & y) ? printf("True ") : printf("False ");
(x && y) ? printf("True ") : printf("False "); CO2
return 0;
}

Solution (i) False (1 marks)


(ii) False (1 marks)

Q A2 Predict the output of the following program:


int main()
{
int x = 65;
printf("%c", x);
return 0;
2 CO2
}

Solution A (2 marks)

Q A3 Draw a flow chart to swap two numbers.


2 CO1

Page 1 of 8
Solution

For logic 1 marks and for correct flow chart(symbols) 1 marks.

Q A4 Predict the output of the following C code.


int main() {
int num = 8;
int result = num << 2;
int result1=num>>2;
printf("After left shift by 2 bits:result= %d\n", result);
printf("After left shift by 2 bits: result1=%d\n", result1); 2 CO2
return 0;
}

Solution (i) After left shift by 2 bits:result= 32 (1 Marks)


(ii) After left shift by 2 bits: result1=2 (1 Marks)

Q A5 Explain NULL pointer in the context of C programming? Provide a concise


definition. Also write the size of a character pointer and size of an integer pointer
on a 32-bit system.
2 CO4
Solution (i) A NULL pointer is a pointer that does not point to any memory
location. It points to NULL. (1 marks)
(ii) 4 Byte (1/2+1/2 marks)
SECTION B
Q B1 Write a C program that performs the following tasks sequentially.

#include <stdio.h>
int main()
{
/*
• Declare a variable named ‘marks’ of type ‘double’. 6 CO3
• Read the value of ‘marks’ from user.
• Prints one the following messages based upon the value of ‘marks’
(i) Prints “Grade A” if ‘marks’ is greater than 90
(ii) Prints “Grade B” if 80 < marks <=90
(iii) Prints “Grade C” if 70 < marks <=80
(iv) prints “Grade Fail” if marks <=70

Page 2 of 8
*/
}// End of Main

Solution #include <stdio.h>

int main() {
// Declare a variable named 'marks' of type 'double'. (1 Marks
double marks;

// Read the value of 'marks' from the user. (1 Marks)


printf("Enter the marks: ");
scanf("%lf", &marks);

// Prints one of the following messages based on the value of 'marks'. (4 marks)
if (marks > 90) {
printf("Grade A\n");
} else if (marks > 80 && marks <= 90) {
printf("Grade B\n");
} else if (marks > 70 && marks <= 80) {
printf("Grade C\n");
} else {
printf("Grade Fail\n");
}

return 0;
}
Q B2 Write an algorithm to check whether a given number is prime or not and draw the
corresponding flowchart.

6 CO1
Solution (i) For correct algorithm (3 Marks)
(ii) For Correct Flowchart (3 Marks)

Q B3 A flowchart is given (shown below) to find and display the square and cube of a
positive number. The execution must be terminated if a negative number is entered.

6 CO1

Page 3 of 8
The above flowchart has some errors which are indicated with (1), (2), (3) and (4).
Answer the following questions to give the correct result.
(a) What will be the correct representation of the box in (1)?
(b) What will be the correct logic for the variable N in (2)?
(c) Out of the flow lines (3) and (4), which one is undesirable?
(d) When all the corrections are made, what will be the output, if the input value is
taken as 12?

Solution (a) The correct representation of the box in (1) is a parallelogram or input/output
box. (1.5 Marks)
(b) The logic for the variable N in (2) will be - If N>0? (1.5 Marks)
(c) Flow line (4) is undesirable. (1.5 Marks)
(d) The output will be 144, 1728. (1.5 marks)

Q B4 Write a C program which performs the following tasks sequentially.


a. Declare a string variable named ‘place’ with a capacity of 100.
b. Using input function read the string value as “Manipal University Jaipur”.
c. Determine the length of string using string library function.
d. Determine the frequency of the character 'a' in the string and display the
count of it.

Solution (a) Char place[100] (1 marks)


(b) gets(place) or fgets (place, sizeof(place), stdin); (1 marks) 6 CO4
(c) int length = strlen(place); (1 Marks)
(d) int count = 0; (3 Marks)
for (int i = 0; i < length; ++i)
{
if (place[i] == 'a')
{
count++;
}
Q B5 Explain the difference between "Call by Value" and "Call by Reference" in the
context of function parameter passing. Illustrate each concept by citing the example 6 CO4

Page 4 of 8
of swapping two numbers.

Solution (a) 2 marks for difference.


(b) (2+2) marks for program of swapping by call by value and call by
reference respectively.
SECTION-C (Analytical Based Questions)
Q C1 Debug and complete the following C program, which is designed to find the
product of the first five prime numbers.
#include <stdio.h>
int main() {
int primes[] = {2, 3, 5, 7, 11};
int product = 1;
// Debug and fix the issues in the for loop
for (int i = 0; i < sizeof(primes); i++) {
product *= primes[i]; }
// Missing logic: Complete the code to display the product of the first five prime
numbers
return 0;
}
Issues to Address: 10 CO3

a. Identify and correct the error in the loop condition that may lead to
accessing memory beyond the array bounds.
b. Debug any logical errors preventing the correct calculation of the product of
the first five prime numbers.
c. Explain why the original loop condition was incorrect and how your
correction addresses the issue.
d. Suggest an alternative loop condition that would also work correctly for
iterating through the array.
Complete the missing logic in the code to display the product of the first five prime
numbers correctly.

Page 5 of 8
Solution (a) The original loop condition i < sizeof(primes) was incorrect. The corrected
condition is i < sizeof(primes) / sizeof(primes[0]), which gives the number
of elements in the array. (2 marks)
(b) The loop logic was correct after fixing the loop condition. (1 marks)
(c) The original loop condition was incorrect because it compared the loop
index i with the total size in bytes of the array. The correction divides the
total size by the size of one array element, ensuring that the loop iterates
over each element. (1 marks)
(d) An alternative loop condition could be i < 5, which directly specifies the
number of elements in the array. This would work correctly for iterating
through the array, given that we know there are five elements. (2 marks)

Q C2
Write a C program that accomplishes the following tasks step by step:
a. Declare three 2-D arrays named "K1," "K2," and "K3" of type "int" with
dimensions 2*2.
b. Read the values for the 2-D arrays "K1" and "K2."
c. Multiply the corresponding elements of "K1" and "K2" and store the results
in the 2-D array "K3."
d. Display the contents of the resulting 2-D array "K3."
Ensure the program is structured to perform these tasks sequentially and provide
the code for each step.

Solution (a) int K1[2][2], K2[2][2], K3[2][2]; ( 1 Marks)


(b) printf("Enter values for matrix K1 (2x2):\n"); ( 3 Marks)
for (int i = 0; i < 2; ++i) 10 CO4
{
for (int j = 0; j < 2; ++j)
{
printf("Enter element K1[%d][%d]: ", i, j);
scanf("%d", &K1[i][j]);
}
}
printf("Enter values for matrix K2 (2x2):\n");
for (int i = 0; i < 2; ++i)
{
for (int j = 0; j < 2; ++j)
{
printf("Enter element K2[%d][%d]: ", i, j);
scanf("%d", &K2[i][j]);
}
}

Page 6 of 8
(c) for (int i = 0; i < 2; ++i) ( 3 Marks)
{
for (int j = 0; j < 2; ++j)
{
K3[i][j] = K1[i][j] * K2[i][j];
}
}

(d) printf("Resultant matrix K3 :\n"); ( 3 marks)


for (int i = 0; i < 2; ++i)
{
for (int j = 0; j < 2; ++j)
{
printf("%d\t", K3[i][j]);
}
printf("\n");
}
SECTION-D
Q D1 #include"stdio.h"
int fun1(int *,int *);
void main()
{
int a=10,b=20,z;
int *p,*q;
p=&a,q=&b;
z=fun1(p,q);
printf("a=%d b=%d p=%d q=%d,\n",a,b,*p,*q);
printf("z=%d\n",z++);
}
int fun1(int *m,int *n)
{
int temp=0,sum=0;
temp=*m;
*m=*n; 10 CO4
*n=temp;
sum=*m+*n;
printf("m=%d n=%d sum=%d\n",*m,*n,sum);
return sum;
}
(i) What value of m,n,sum will be printed?
(ii) What value of a,b,p,q will be printed?
(iii) What value of z will be printed?

Solution (i) m=20 n=10 sum=30 (1.5+1.5+1.5 Marks)


(ii) a=20 b=10 p=20 q=10, ( 1+1+1+1 Marks)
(iii) z=30

Page 7 of 8
Q D2 Consider a scenario where you are tasked with developing a program in C to
manage employee inventory. The program should utilize structures to handle
employee information. The program should perform the following tasks:

a. Define a structure named Employee with the following attributes:


Employee_ID (integer)
First_Name (string)
Salary (float)
b. Create a structure to store information of 2 employees in the inventory.
c. Display the information of both the employees.
Solution (a) struct Employee ( 2 marks)
{
int Employee_ID;
char First_Name[50];
float Salary;
};

(b) // Create structures to store information for 2 employees ( 5 marks)


struct Employee employee1, employee2;

// Input information for employee1


printf("Enter details for Employee 1:\n");
printf("Employee ID: ");
scanf("%d", &employee1.Employee_ID); 10 CO5
printf("First Name: ");
scanf("%s", employee1.First_Name);
printf("Salary: ");
scanf("%f", &employee1.Salary);

// Input information for employee2


printf("\nEnter details for Employee 2:\n");
printf("Employee ID: ");
scanf("%d", &employee2.Employee_ID);
printf("First Name: ");
scanf("%s", employee2.First_Name);
printf("Salary: ");
scanf("%f", &employee2.Salary);

(c) // Display information of both employees (3 Marks)


printf("\nEmployee 1 Details:\n");
printf("Employee ID: %d\n", employee1.Employee_ID);
printf("First Name: %s\n", employee1.First_Name);
printf("Salary: %.2f\n", employee1.Salary);

printf("\nEmployee 2 Details:\n");
printf("Employee ID: %d\n", employee2.Employee_ID);
printf("First Name: %s\n", employee2.First_Name);
printf("Salary: %.2f\n", employee2.Salary);

Page 8 of 8

You might also like