Você está na página 1de 2

Assignment for 10 marks; Due date 1st November;

Handwritten; Individual .
Q.1 Write a program that asks the user for a 24 hour time, then displays the time in 12 hour
form:
Sample Run:
Enter a 24 hour time: 21 11
Equivalent 12 hour time: 9
11 PM
Q.2 Write a program that counts the number of digits in an integer entered by the user. Find its
sum and tell whether the number is prime or not.
Sample Run:
Enter an integer: 12340 [ENTER]
No. of digits = 4
Sum of digits = 10
The entered number 12340 is not prime.
Q.3 Write a program that computes the table of the number entered by the user and square and
cube of each calculated number.
Sample Run:
Enter an integer: 2 [ENTER]
Squar
e
Cube
2
x
1
=
2
4
8
2
x
2
=
4
16
64
2
x
3
=
6
36
216
2
x
4
=
8
64
512
2
x
5
=
10
100
1000
2
x
6
=
12
144
1728
2
x
7
=
14
196
2744
2
x
8
=
16
256
4096
2
x
9
=
18
324
5832
2
x
10
=
20
400
8000
Q.4 Write a program that calculates the factorial of a positive integer given by the user.
Sample Run:
Enter a positive integer: 6
[ENTER]
Factorial of 6 =
720
Q.5 Write a program that asks the user for a 12 hour time, then displays the time in 24 hour
form:
Sample Run:
Enter a 12 hour time: 9
11 PM
Equivalent 24 hour time: 21 11
Q.6 Write a program that generates a sequence of numbers which are multiples of the no. which
is entered by the user. The sequence will run to the no which is also entered by the user.
Sample Run:
Enter limit of sequence: 100
[ENTER]
Enter a no. : 12
[ENTER]
12 24 36 48 60 72 84 96
Q.7 Write a program that computes sin, cos and tan of the angle 0 o to 180o.
Sample Run:
Enter an integer: 2 [ENTER]
cos
tan
sin
0
=
0
1
0
0.017
0.999
0.017
1
=
4
8
4
0.034
0.349
2
=
8
0.993
2
.
=
.
.
.
.
=
.
.
.
180
=
0
-1
0
Q.8 Write a program that determines whether a number supplied by user is positive, negative, zero, even or odd.
Sample Run:
Enter an integer: -67
[ENTER]
You entered a negative and odd integer.
Q.9 Write a calculator program using if()-else for the given operator (+ , - ,* , / ,cos , sin , tan ).
Q.10 Write programs to print the following patterns using for loops (do not use if, if else or any
other decision making statement).

1
121
12321
1234321
Q.11 Write a single C statement to accomplish each of the following:
a) Define the variables c, thisVariable, q76354 and number to be of type int.
b) Prompt the user to enter an integer. End your prompting message with a colon (:) followed by
a space and leave the cursor positioned after the space.
c) Read an integer from the keyboard and store the value entered in integer variable a.
d) If number is not equal to 7, print "The variable number is not equal to 7."
e) Print the message "This is a C program." on one line.
f) Print the message "This is a C program." on two lines so that the first line ends with C.
g) Print the message "This is a C program." with each word on a separate line.
h) Print the message "This is a C program." with the words separated by tabs.
Q.12 Write a program that inputs three different integers from the keyboard, then prints the sum,
the average, the product, the smallest and the largest of these numbers.
The screen dialogue should appear as follows:
Input three different integers: 13 27 14
Sum is 54
Average is 18
Product is 4914
Smallest is 13
Largest is 27
Q.13 Identify and correct the errors in each of the following statements. (Note: There may be
more than one error per statement.)
a) scanf( "d", value );
b) printf( "The product of %d and %d is %d"\n, x, y );
c) firstNumber + secondNumber = sumOfNumbers
d) if ( number => largest )
largest == number;
e) */ Program to determine the largest of three integers /*
f) Scanf( "%d", anInteger );
g) printf( "Remainder of %d divided by %d is\n", x, y, x % y );
h) if ( x = y );
printf( %d is equal to %d\n", x, y );
i) print( "The sum is %d\n," x + y );
j) Printf( "The value you entered is: %d\n, &value );
Q.14 (Diameter, Circumference and Area of a Circle) Write a program that reads in the radius of
a circle and prints the circles diameter, circumference and area. Use the constant value 3.14159
for .
Q.15 What, if anything, prints when each of the following statements is performed? If nothing
prints, then answer Nothing. Assume x = 2 and y = 3.
a) printf( "%d", x );
b) printf( "%d", x + x );
c) printf( "x=" );
d) printf( "x=%d", x );
e) printf( "%d = %d", x + y, y + x );
f) z = x + y;
g) scanf( "%d%d", &x, &y );
h) /* printf( "x + y = %d", x + y ); */
i) printf( "\n" );
Q.16 (Separating Digits in an Integer) Write a program that inputs one five-digit number,
separates the number into its individual digits and prints the digits separated from one another
by three spaces each. For example,
if the user types in 42139, the program should print 4 2 1 3 9

Você também pode gostar