Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

PRACTICE ASSIGNMENTS

-by PRASENJIT SIR and RAJEEB SIR


1)Write a program to swap the value of two variable.
a) Using temporary variable
b) Without using temporary variable
c)Using bitwise operator*
2)write a program that takes a number as input and calculate the sum of digits
3)Write a C Program to Check Whether a Number is Palindrome or Not.
Palindrome number: A palindromic number is a number that stays the same
when its digits are reversed.
4)Write a C program to find out whether a given year is a leap year or not.
5)Write a C program to check sign of a given number
6)Write a C program to check whether a given positive number is a multiple of
3 or a multiple of 7.
7)Program to check whether a person is eligible to vote or not.
A person is eligible to vote if his/her age is greater than or equal to 18.
8)Write a C Program to calculate the grade of the student according to the
specified marks.
9) Predict the output of the following C program
#include <stdio.h>
int main()
{
int y;
int x = 2;
y = (x >= 6) ? 6 : x;
printf("y =%d ",y);
return 0;
}
10) 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;
}
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.

18) Write a C program to accept a coordinate point in a XY coordinate system


and determine in which quadrant the coordinate point lies.
Test Data : 7 9
Expected Output :
The coordinate point (7,9) lies in the First quadrant.
19) Write a C program to find the eligibility of admission for a professional
course based on the following criteria: Go to the editor
Eligibility Criteria : Marks in Maths >=65 and Marks in Phy >=55 and Marks in
Chem>=50 and Total in all three subject >=190 or Total in Maths and Physics
>=140 ------------------------------------- Input the marks obtained in Physics :65
Input the marks obtained in Chemistry :51 Input the marks obtained in
Mathematics :72 Total marks of Maths, Physics and Chemistry : 188 Total
marks of Maths and Physics : 137 The candidate is not eligible.
Expected Output :
The candidate is not eligible for admission.
20) Write a C program to calculate the root of a Quadratic Equation.
Test Data : 1 5 7
Expected Output :
Root are imaginary;
21) Write a C program to read roll no, name and marks of three subjects and
calculate the total, percentage and division.
Test Data :
Input the Roll Number of the student :784
Input the Name of the Student :James
Input the marks of Physics, Chemistry and Computer Application : 70 80 90
Expected Output :v
Roll No : 784
Name of Student : James
Marks in Physics : 70
Marks in Chemistry : 80v
Marks in Computer Application : 90
Total Marks = 240
Percentage = 80.00
Division = First
22) Write a C program to read temperature in centigrade and display a suitable
message according to temperature state below :
Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot
Temp >=40 then Its Very Hot
Test Data :
42
Expected Output :
Its very hot.
23) Write a C program to check whether a triangle is Equilateral, Isosceles or
Scalene.
Test Data :
50 50 60
Expected Output :
This is an isosceles triangle.
24) Write a C program to check whether a character is an alphabet, digit or
special character.
Test Data :@
Expected Output :
This is a special character.
25) Write a C program to check whether an alphabet is a vowel or consonant.
Test Data :k
Expected Output :
The alphabet is a consonant.
26) Write a C program to calculate profit and loss on a transaction.
Test Data :500 700
Expected Output :
your profit amount : 200

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

You might also like