Class- Sample Questions (April 3, 2015) Question 1: In the following

advertisement
Class- Sample Questions (April 3, 2015)
Question 1: In the following program there are some syntax errors. Find the errors and write their
correct forms in the table given below.
1#include stdio.h
2 void Main()
3{
4 int m,x,b,y,
5 scanf(“%d%d%d”,m,x,b);
6 y=mx+b;
7 if(x=y=0)
8 {
9
printf(“In the middle of the axis is origin, which has coordinates 0,0”);
10 }
11 else
12
printf(“The point has the following coordinates: %c, % c”,x,y);
13 }
14 }
Line #
Correct Forms
Question 2: Write a program that reads an integer from the keyboard and displays a 1 if it is divisible
by 3 or a 0(zero) otherwise.
Question 3: What does the following program print?
#include<stdio.h>
void main()
{
int x, y, z ;
x = 30;
y = 5;
z = x / y;
printf( “%d\n”, z );
z= x – y * 2;
printf( “%d\n”, z );
}
1
Question 4: Write a C program that reads in five integers and then determines and prints the largest
and the smallest integers in the group. Use only the programming techniques you have learned in the
class.
Sample run
Input 5 integers: 9 4 5 8 7
The largest value is 9
The smallest value is 4
Question 5: Write a C program that calculates the amount of time in seconds between two times
(reads the time as three integer numbers for hours, minutes, and seconds), both of which are
within one 24-hour cycle of the clock. Note that the second time should be greater than the first
time.
Sample run:
Enter the first time as three integers: 4 20 39
Enter the second time as three integers: 7 20 39
The difference between the times is 10800 seconds
Question 6: Write a program that will read day of week as integer between 0 and 6, then prints the
corresponding day of the week. Assume that the first day of the week (0) is Sunday.
Question 7: Given a point, a line from the point forms an angle with the horizontal axis to the right of
the line. The line is said to terminate in one of four quadrants based on its angle (a) from the horizontal,
as shwon as follows
y axis
Q2
Q1
x axis
Q3
Q4
Write a program that determines(prints) the quadrant, given a user input angle. Note: if the angle is
exactly 00, it is not in a quadrant but lies on the positive X axis; if it is exactly 900, it lies on the positive
Y axis; and if it is exactly 1800 , it lies on the negative X axis ;and if it is exactly 2700 , it lies on the
negative Y axis.
2
Question 8: What output is generated by the following code segment?
int x=4;
if( 7 > x > 2 )
printf("True");
else
printf("False");
Question 10: Evaluate the following expressions to 0(false) or 1(true). Show how you arrived at your
answer.
a) !(3+3) >= 6
b) 1+6 = =7 || 3+2 = = 1
Question 11: Write a program that accepts the lengths of three sides of a triangle as inputs. The program output
should indicate whether or not the triangle is an equilateral triangle.. (Hint: an equilateral triangle is a triangle in
which all three sides are equal)
Q2)Write a program that asks the user for a two-digt integer number greater than 19 and less than 100,
then prints the English word for the number. You program is expected to run as following sample run.
Sample Run:
Enter a two-digit number: 46
You entered "fourty-six".
Hint:Break the number into two digits.
3
Download