0% found this document useful (0 votes)
40 views2 pages

Quiz II: Computer Programming (MA511) : 1), For Unsigned Int: (0 To 2 1)

This document contains a 10 question quiz on computer programming in C. It covers topics such as: 1) The differences between integer, character, and string constants. 2) The function of semicolons in C statements. 3) The #include directive for standard input/output functions. 4) Issues with expressions like i = i++. 5) The smallest and largest values storable in 8-bit signed and unsigned integer variables. 6) Conditions for printing "ice", "water", or "steam" based on temperature. 7) What code prints and in what order. 8) A program to count numbers between 1-777 that are

Uploaded by

Naveen Gupta
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)
40 views2 pages

Quiz II: Computer Programming (MA511) : 1), For Unsigned Int: (0 To 2 1)

This document contains a 10 question quiz on computer programming in C. It covers topics such as: 1) The differences between integer, character, and string constants. 2) The function of semicolons in C statements. 3) The #include directive for standard input/output functions. 4) Issues with expressions like i = i++. 5) The smallest and largest values storable in 8-bit signed and unsigned integer variables. 6) Conditions for printing "ice", "water", or "steam" based on temperature. 7) What code prints and in what order. 8) A program to count numbers between 1-777 that are

Uploaded by

Naveen Gupta
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/ 2

Quiz II: Computer Programming (MA511)

1. What is the difference between the constants 123, ‘1’, and “123” ? [1]

123: an integer, ‘1’: a character “123”: string.


Ans.

2. What is the function of the semicolon in a C statement ? [1]

semicolon implies end of an expression.


Ans.

3. What is the line #include< stdio.h > at the top of a C source file for ? [1]

for standard input output library function.


Ans.

4. What would the expression i = i++ do ? [1]

its an invalid expression since at the same time i is increasing and assigning to itself.
Ans.

5. What are the largest and smallest values that can be reliably stored in a variable of type
signed int and unsigned int in a 8 bit machine ? [2]

for signed int: (−27 to +27 − 1), for unsigned int: (0 to 28 − 1)


Ans.

6. Under what conditions will this code print (i) water (ii) steam ? [2]
if(T < 32)
printf(“ice\n”); Ans:
else if(T < 212) (i) water :32 ≤ T < 212
printf(“water\n”); (ii) steam :212 ≤ T
else printf(“steam\n”);
7. What would this code print ? [2]
Ans:
int i;
a
for(i = 0; i < 3; i = i + 1)
a
printf(“a\n”);
a
printf(“b\n”);
b
printf(“c\n”);
c

8. Write a C program to find out how many of the numbers from 1 to 777 are greater than 7
and divisible by 7 ? [2]
#include < stdio.h >
main(){
int i, count=0;
for(i = 0; i <= 777; i = i + 1){
if((i > 7)&&(i%7 == 0)){
Ans. count=count+1;
//printf (“%d, %d\n”, i, count);
}
}
printf (“%d\n”, count);
}

9. Write a C program to compute the average of the numbers (x) which are perfect square and
x ∈ [1, 1024] ? [2]

#include < stdio.h >


#include < math.h >
main(){
int i, count=0, sum =0;
for(i = 1; i <= 1024; i = i + 1){
if( ((float)sqrt(i))==sqrt(i)){
Ans. count=count+1;
sum=sum+i;
}
}
printf (“Average := %d\n”, sum/count);
}

10. Write a program that takes a line of string as input and print the line in reverse order. [2]

#include < stdio.h >


#include < string.h >
main(){
char name[100], eman[100];
int i, j, length;
printf(“Enter the string: ”);
Ans. scanf(“%[∧ \n]”, name);
length=strlen(name);
for(i = length, j = 0; 0 <= i, j <= length; i = i − 1, j = j + 1)
eman[j]=name[i];
for(i = 0; i <= length; i = i + 1)
printf(“%c”, eman[i]);
}

You might also like