0% found this document useful (0 votes)
84 views7 pages

PSUC Sessional-1 Oct 22 Scheme of Evaluation

This document contains a scheme of evaluation for a multiple choice and descriptive question test on C programming. The multiple choice section contains 10 questions testing various concepts in C like syntax errors, input/output functions, operators, conditional statements, loops, and break/continue keywords. The descriptive section contains 4 questions. Question 11 asks to draw a flowchart to count divisors of a number. Question 12 explains the conditional operator and provides an equivalent code snippet. Question 13 provides a complete C program to spell out digits of a number. Question 14 discusses enumerated data types with an example and provides a program to display and sum odd numbers using a for loop.

Uploaded by

dreamivory29
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)
84 views7 pages

PSUC Sessional-1 Oct 22 Scheme of Evaluation

This document contains a scheme of evaluation for a multiple choice and descriptive question test on C programming. The multiple choice section contains 10 questions testing various concepts in C like syntax errors, input/output functions, operators, conditional statements, loops, and break/continue keywords. The descriptive section contains 4 questions. Question 11 asks to draw a flowchart to count divisors of a number. Question 12 explains the conditional operator and provides an equivalent code snippet. Question 13 provides a complete C program to spell out digits of a number. Question 14 discusses enumerated data types with an example and provides a program to display and sum odd numbers using a for loop.

Uploaded by

dreamivory29
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

SCHEME of EVALUATION

Type: MCQ

Q1. When the program violates the rules of the programming language it generates _______.
(0.5)

1. Logical Errors
2. **Syntax Errors
3. Semantic Errors
4. Runtime Errors
Q2. Which among the following is the correct syntax for printing and reading two integer
numbers? (0.5)
1. printf(%d%d, number1,number2);
scanf(%d%d,&number1,&number2);
2. printf(%d ,%d, number1, number2);
scanf(%d ,%d, &number1, &number2);
3. **printf(“%d%d”, number1, number2);
scanf(“%d%d”,&number1,&number2);
4. printf(“%d%d”,&number1,& number2);
scanf(“%d%d”, number1, number2);

Q3. What is the output of Left Shift Operator << on a 8-bit number 9<<3? (0.5)

1. 00001000
2. 00000001
3. **01001000
4. 00100100

Q4. What is the output of the error-free C code snippet.? (0.5)


#include<stdio.h>
int main(){
int n=0;
n = 9>2 ? n++ : 3;
printf("%d",n);
return 0;
}

1. **0
2. 4
3. 1
4. 3
Q5. What is the output of the below C code snippet? (0.5)
#include<stdio.h>
int main()
{
int n=10,n1=10;
if(n=n1/2==5)
printf("%d",n);
else
printf("Hello");
}

1. 10
2. **1
3. Hello
4. Compilation error
Q6. What will be the output of the following C code? (0.5)
#include<stdio.h>
void main()
{
int ch=2;
switch (ch)
{
default:
printf("Nothing");
case 1:
printf("Try");
break;
printf("Hi");
printf("MIT");
}
1. Nothing
2. HiMIT
3. MIT
4. **NothingTry
Q7. What is the output of the given below program? (0.5)
#include<stdio.h>
int main()
{
int i;
for (i=0; i<3; i++);
{
printf("%d", i);
}
return 0;
}
1. 1234
2. 0123
3. **3
4. 4

Q8. How many times i value is checked in the following C code? (0.5)
#include <stdio.h>
int main() {
int i = 0;
do {
i++;
printf("correct answer\n");
} while (i < 3);
}
1. 2
2. **3
3. 4
4. 1

Q9. What will be the output of the following C code? (0.5)


#include <stdio.h>
void main()
{
int x = 5;
if (x < 1);
printf("hello");
if (x == 5)
printf("hi");
else
printf("no");
}

1. hi
2. **hellohi
3. no
4. error
Q10. The C code for(;;) represents an infinite loop. Loop can be terminated by_________ (0.5)
a) **break
b) continue
c) return
d) exit(0)
Type: DES
Q11. Draw a flowchart to count the number of divisors, other than 1 and the number itself,
for a given positive integer (number) N (E.g. for number 6 the divisors are 1, 2, 3 and 6. So the
number of divisors is 2, excluding 1 and 6). (2)
Q12. Using the syntax of conditional operator, briefly explain it’s working. Write the
equivalent code for the code snippet below using the conditional operator. (2)
if(year%4 == 0)
{
if( year%100 == 0)
{
if (year%400 == 0)
printf("%d is a leap year",year);
else
printf("%d is not a leap year",year);
}else printf("%d is a leap year",year);
}else printf("%d is not a leap year",year);

Conditional Operator
condition ? expression1 : expression2
• condition is an expression that is evaluated first.
• If the result of the evaluation of condition is TRUE (nonzero), then expression1 is
evaluated and the result of the evaluation becomes the result of the operation.
• If condition is FALSE (zero), then expression2 is evaluated and its result becomes
the result of the operation.
Example:
maxValue = ( a > b ) ? a : b;
Equivalent to:
if ( a > b )
maxValue = a;
else
maxValue = b;
[syntax – ½ marks and brief explanation – ½ marks]

Equivalent code snippet using conditional operator


(year%4==0) ?
(year%100==0?
(year%400==0 ? printf("The year %d is a leap year",year)
:printf("The year %d is not a leap year",year))
: printf("The year %d is a leap year",year))
: printf("The year %d is not a leap year",year);
[correct code - 1 marks; partially correct – ½ marks]
Q13. Write a C Program to spell each digit name of a number read from the keyboard using a
switch case. ( if the read number is 12300 then the output should be: one two three zero
zero). (3)
#include <stdio.h>
#include <math.h>
int main()
{
int n, num = 0, digits=0,num1=0,digits1=0;
// Input number
printf( "Enter any number to print in words: \n");
scanf("%d", &n);
while(n != 0)
{
num = (num * 10) + (n % 10);
n /= 10;
digits++;
}
n=num;
while(n>0)
{
num1 = (num1 * 10) + (n % 10);
n /= 10;
digits1++;
}
// Find total trailing zeros
digits = digits - digits1;
//Extract last digit of number and print corresponding number in words till num becomes 0
while(num != 0)
{
switch(num % 10)
{
case 0:
printf("Zero ");
break;
case 1:
printf("One ");
break;
case 2:
printf("Two ");
break;
case 3:
printf("Three ");
break;
case 4:
printf("Four ");
break;
case 5:
printf("Five ");
break;
case 6:
printf("Six ");
break;
case 7:
printf("Seven ");
break;
case 8:
printf("Eight ");
break;
case 9:
printf("Nine ");
break;
}
num /= 10;
}
//Print all trailing zeros
while( digits)
{
printf("Zero ");
digits--;
}
return 0;
}
[declaration + reading the number-0.5; Reverse the number 0.5 ; Finding and printing the
trailing zeros 0.5; Usage of switch statement to spell the digit name 1; Rest logic  0.5]

Q14. Discuss enumerated datatype with an example. Write a C program to display the n odd
natural numbers and their sum using for loop.(3)

enum identifier { value1, value2,..,value };


n

• Here, identifier is the name of enumerated data type or tag.


And value1, value2,....,valueN are values of type identifier.
• By default, value1 will be equal to 0, value2 will be 1 and so on but, the programmer can
change the default value.
enum card {club, diamonds, hearts, spades};
enum card {club=0, diamonds, hearts=20, spades};
enum card shape, s1;
shape = hearts;
s1 = spades;

#include <stdio.h>
int main() {
int i,n,sum=0;
printf("Input number of terms : ");
scanf("%d",&n);
printf("\nThe odd numbers are :");
for(i=1;i<=n;i++) {
printf("%d ",2*i-1);
sum+=2*i-1;
}
printf("\nThe Sum of odd Natural Number upto %d terms : %d
\n",n,sum);
return 0;
}
[enum – 1 marks; Declaration & reading – ½ marks; looping (logic) – 1 mark; results(outputs)
– ½ marks]

You might also like