Professional Documents
Culture Documents
Practice Assignments: - by Prasenjit Sir and Rajeeb Sir
Practice Assignments: - by Prasenjit Sir and Rajeeb Sir
#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z = (y++) ? y == 1 && x : 0;
printf("%d\n", z);
return 0;
}
11) What will be the output of the following C program
#include <stdio.h>
int main()
{
int x = 1, y = 0, z = 3;
return x > y ? printf("%d", z) : z;
}
12) What is the output of the following C program
#include <stdio.h>
int main()
{
int m = 5, n = 4;
(m > n) ? printf("m is greater than n that is %d > %d",m, n): printf("n is greater
than m that is %d>%d",n, m);
return 0;
}
13) What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z = (++y) ? y == 1 && x : 0;
printf("%d\n", z);
return 0;
14) We know that any numbers that are not equal to 0 are viewed as true in C,
so we can write:
Test the given program
int a = 16;
while (a--)
printf("%d\n", a); // prints numbers from 15 to 0
15) We know that any numbers that are not equal to 0 are viewed as true in C,
so we can write:
int a = 16;
while (a--)
printf("%d\n", a); // prints numbers from 15 to 0
Or
We know that any numbers that are not equal to 0 are viewed as true in C, so
we can write:
int a = 16;
while (a> 0)
{
printf("%d\n", a);
a--;
}
Does both the program is same?
16) Write a C program to read the value of an integer m and display the value
of n is 1 when m is larger than 0, 0 when m is 0 and -1 when m is less than 0.
Test Data: -5
Expected Output:
The value of n = -1
17) Write a C program to accept the height of a person in centimeter and
categorize the person according to their height.
Test Data : 135
Expected Output :
The person is Dwarf.
27) Write a program in C to calculate and print the Electricity bill of a given
customer. The customer id., name and unit consumed by the user should be
taken from the keyboard and display the total amount to pay to the customer.
The charge are as follow :
Unit Charge/unit
upto 199 @1.20
200 and above but less than 400 @1.50
400 and above but less than 600 @1.80
600 and above @2.00
If bill exceeds Rs. 400 then a surcharge of 15% will be charged and the
minimum bill should be of Rs. 100/-
Test Data :
1001
James
800
Expected Output :
Customer IDNO :1001
Customer Name :James
unit Consumed :800
Amount Charges @Rs. 2.00 per unit : 1600.00
Surchage Amount : 240.00
Net Amount Paid By the Customer : 1840.00
28) Write a program in C to read any day number in integer and display day
name in the word.
Test Data :
4
Expected Output :
Thursday
29) Write a program in C to read any digit, display in the word.
Test Data :
4
Expected Output :
Four
30) Write a program in C to read any Month Number in integer and display
Month name in the word.
Test Data :4
Expected Output :
April
31) Write a program in C to read any Month Number in integer and display the
number of days for this month.
Test Data :7
Expected Output :
Month have 31 days
32) Write a program in C which is a Menu-Driven Program to compute the area
of the various geometrical shape.
Test Data :
1
5
Expected Output :
The area is : 78.500000
33) Write a program in C which is a Menu-Driven Program to perform a simple
calculation.
1. For circle
2. For rectangle
3. For triangle
34) What will be the output of the following program:
#include < stdio.h >
int main()
{
int tally=0;
for(;;)
{
if(tally==10)
break;
printf("%d ",++tally);
}
return 0;
}
35) What is the output of the following C program.
#include <stdio.h>
void main()
{
int i,j,charVal='A';
for(i=5;i>=1;i--)
{
for(j=0;j< i;j++)
printf("%c ",(charVal+j));
printf("\n");
}
}
36) Write a program in C to display the first 10 natural numbers.
Expected Output :
1 2 3 4 5 6 7 8 9 10
37) Write a C program to find the sum of first 10 natural numbers.
Expected Output :
The first 10 natural number is :
1 2 3 4 5 6 7 8 9 10
The Sum is : 55
38) Write a program in C to display n terms of natural number and their sum.
Test Data : 7
Expected Output :
The first 7 natural number is :
1234567
The Sum of Natural Number upto 7 terms : 28
39)Write a program in C to read 10 numbers from keyboard and find their sum
and average
40) Write a program in C to display the cube of the number upto given an
integer.
Test Data :
Input number of terms : 5
Expected Output :
Number is : 1 and cube of the 1 is :1
Number is : 2 and cube of the 2 is :8
Number is : 3 and cube of the 3 is :27
Number is : 4 and cube of the 4 is :64
Number is : 5 and cube of the 5 is :125
41)Write a program in C to display the multiplication table of a given integer.
Test Data :
Input the number (Table to be calculated) : 15
Expected Output :
15 X 1 = 15
...
...
15 X 10 = 150
41) Write a program in C to display the multipliaction table vertically from 1 to
n.
Test Data :
Input upto the table number starting from 1 : 8
Expected Output :
Multiplication table from 1 to 8
1x1 = 1, 2x1 = 2, 3x1 = 3, 4x1 = 4, 5x1 = 5, 6x1 = 6, 7x1 = 7, 8x1 = 8
...
1x10 = 10, 2x10 = 20, 3x10 = 30, 4x10 = 40, 5x10 = 50, 6x10 = 60, 7x10 = 70,
8x10 = 80
42) Write a program in C to display the n terms of odd natural number and
their sum .
Test Data
Input number of terms : 10
Expected Output :
The odd numbers are :1 3 5 7 9 11 13 15 17 19
The Sum of odd Natural Number upto 10 terms : 100
INPUT ROWS
43)Write a program in C to display the pattern like right angle triangle using an
asterisk.
The pattern like :
*
**
***
*****
.
.
.
44) Write a program in C to display the pattern like right angle triangle with a
number.
The pattern like :
1
12
123
1234
Take number of rows as input
45) 8. Write a program in C to make such a pattern like right angle triangle with
a number which will repeat a number in a row.
The pattern like :
1
22
333
4444
46) Write a program in C to make the following pattern.
1
23
456
7 8 9 10
46) Write a program in C to make the following pyramid.
1
23
456
7 8 9 10