C Exercises For Condition

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 10

C Conditional Statement [26 exercises with solution]

1. Write a C program to accept two integers and check whether they are equal or
not. Go to the editor
Test Data : 15 15
Expected Output :
Number1 and Number2 are equal

2. Write a C program to check whether a given number is even or odd. Go to the


editor
Test Data : 15
Expected Output :
15 is an odd integer

3. Write a C program to check whether a given number is positive or negative. Go to


the editor
Test Data : 15
Expected Output :
15 is a positive number.

4. Write a C program to find whether a given year is a leap year or not. Go to the
editor
Test Data : 2016
Expected Output :
2016 is a leap year.

5. Write a C program to read the age of a candidate and determine whether it is


eligible for casting his/her own vote. Go to the editor
Test Data : 21
Expected Output :
Congratulation! You are eligible for casting vote.

6. 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. Go to the
editor
Test Data : -5
Expected Output :
The value of n = -1

7. Write a C program to accept the height of a person in centimeter and categorize


the person according to their height. Go to the editor
Test Data : 135
Expected Output :
The person is Dwarf.

8. Write a C program to find the largest of three numbers. Go to the editor


Test Data : 12 25 52
Expected Output :
1st Number = 12, 2nd Number = 25, 3rd Number = 52
The 3rd Number is the greatest among three.

9. Write a C program to accept a coordinate point in a XY coordinate system and


determine in which quadrant the coordinate point lies. Go to the editor
Test Data : 7 9
Expected Output :
The coordinate point (7,9) lies in the First quadrant.

10. Write a C program to find the eligibility of admission for a professional


course based on the following criteria: Go to the editor
Marks in Maths >=65
Marks in Phy >=55
Marks in Chem>=50
Total in all three subject >=180
or
Total in Math and Subjects >=140

Test Data :
Input the marks obtained in Physics :65
Input the marks obtained in Chemistry :51
Input the marks obtained in Mathematics :72
Expected Output :
The candidate is eligible for admission.
Click me to see the solution

11. Write a C program to calculate the root of a Quadratic Equation. Go to the


editor
Test Data : 1 5 7
Expected Output :
Root are imaginary;
No solution.

12. Write a C program to read roll no, name and marks of three subjects and
calculate the total, percentage and division. Go to the editor
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 :
Roll No : 784
Name of Student : James
Marks in Physics : 70
Marks in Chemistry : 80
Marks in Computer Application : 90
Total Marks = 240
Percentage = 80.00
Division = First

13. Write a C program to read temperature in centigrade and display a suitable


message according to temperature state below : Go to the editor
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.
Click me to see the solution

14. Write a C program to check whether a triangle is Equilateral, Isosceles or


Scalene. Go to the editor
Test Data :
50 50 60
Expected Output :
This is an isosceles triangle.
15. Write a C program to check whether a triangle can be formed by the given value
for the angles. Go to the editor
Test Data :
40 55 65
Expected Output :
The triangle is not valid.

16. Write a C program to check whether a character is an alphabet, digit or special


character. Go to the editor
Test Data :
@
Expected Output :
This is a special character.

17. Write a C program to check whether an alphabet is a vowel or consonant. Go to


the editor
Test Data :
k
Expected Output :
The alphabet is a consonant.

18. Write a C program to calculate profit and loss on a transaction. Go to the


editor
Test Data :
500 700
Expected Output :
You can booked your profit amount : 200
Click me to see the solution

19. 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 : Go to the editor

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

20. Write a program in C to accept a grade and declare the equivalent description :
Go to the editor
Grade Description
E Excellent
V Very Good
G Good
A Average
F Fail
Test Data :
Input the grade :A
Expected Output :
You have chosen : Average.

21. Write a program in C to read any day number in integer and display day name in
the word. Go to the editor
Test Data :
4
Expected Output :wednesday

22. Write a program in C to read any digit, display in the word. Go to the editor
Test Data :
4
Expected Output :
Four

23. Write a program in C to read any Month Number in integer and display Month name
in the word. Go to the editor
Test Data :
4
Expected Output :
April

24. Write a program in C to read any Month Number in integer and display the number
of days for this month. Go to the editor
Test Data :
7
Expected Output :
Month have 31 days.

25. Write a program in C which is a Menu-Driven Program to compute the area of the
various geometrical shape. Go to the editor
Test Data :
1
5
Expected Output :
The area is : 78.500000

26. Write a program in C which is a Menu-Driven Program to perform a simple


calculation. Go to the editor
Test Data :
10
2
3
Expected Output :
The Multiplication of 10 and 2 is: 20
Write a C program to find maximum between two numbers.
Write a C program to find maximum between three numbers.
Write a C program to check whether a number is negative, positive or zero.
Write a C program to check whether a number is divisible by 5 and 11 or not.
Write a C program to check whether a number is even or odd.
Write a C program to check whether a year is leap year or not.
Write a C program to check whether a character is alphabet or not.
Write a C program to input any alphabet and check whether it is vowel or consonant.
Write a C program to input any character and check whether it is alphabet, digit or
special character.
Write a C program to check whether a character is uppercase or lowercase alphabet.
Write a C program to input week number and print week day.
Write a C program to input month number and print number of days in that month.
Write a C program to count total number of notes in given amount.
Write a C program to input angles of a triangle and check whether triangle is valid
or not.
Write a C program to input all sides of a triangle and check whether triangle is
valid or not.
Write a C program to check whether the triangle is equilateral, isosceles or
scalene triangle.
Write a C program to find all roots of a quadratic equation.
Write a C program to calculate profit or loss.
Write a C program to input marks of five subjects Physics, Chemistry, Biology,
Mathematics and Computer. Calculate percentage and grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
Write a C program to input basic salary of an employee and calculate its Gross
salary according to following:
Basic Salary <= 10000 : HRA = 20%, DA = 80%
Basic Salary <= 20000 : HRA = 25%, DA = 90%
Basic Salary > 20000 : HRA = 30%, DA = 95%
Write a C program to input electricity unit charges and calculate total electricity
bill according to the given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit

Basic exerecises

Write a C program to perform input/output of all basic data types.


Write a C program to enter two numbers and find their sum.
Write a C program to enter two numbers and perform all arithmetic operations.
Write a C program to enter length and breadth of a rectangle and find its
perimeter.
Write a C program to enter length and breadth of a rectangle and find its area.
Write a C program to enter radius of a circle and find its diameter, circumference
and area.
Write a C program to enter length in centimeter and convert it into meter and
kilometer.
Write a C program to enter temperature in Celsius and convert it into Fahrenheit.
Write a C program to enter temperature in Fahrenheit and convert to Celsius
Write a C program to convert days into years, weeks and days.
Write a C program to find power of any number x ^ y.
Write a C program to enter any number and calculate its square root.
Write a C program to enter two angles of a triangle and find the third angle.
Write a C program to enter base and height of a triangle and find its area.
Write a C program to calculate area of an equilateral triangle.
Write a C program to enter marks of five subjects and calculate total, average and
percentage.
Write a C program to enter P, T, R and calculate Simple Interest.
Write a C program to enter P, T, R and calculate Compound Interest.
Write a C program to print all natural numbers from 1 to n. - using while loop
Write a C program to print all natural numbers in reverse (from n to 1). - using
while loop
Write a C program to print all alphabets from a to z. - using while loop
Write a C program to print all even numbers between 1 to 100. - using while loop
Write a C program to print all odd number between 1 to 100.
Write a C program to find sum of all natural numbers between 1 to n.
Write a C program to find sum of all even numbers between 1 to n.
Write a C program to find sum of all odd numbers between 1 to n.
Write a C program to print multiplication table of any number.
Write a C program to count number of digits in a number.
Write a C program to find first and last digit of a number.
Write a C program to find sum of first and last digit of a number.
Write a C program to swap first and last digits of a number.
Write a C program to calculate sum of digits of a number.
Write a C program to calculate product of digits of a number.
Write a C program to enter a number and print its reverse.
Write a C program to check whether a number is palindrome or not.
Write a C program to find frequency of each digit in a given integer.
Write a C program to enter a number and print it in words.
Write a C program to print all ASCII character with their values.
Write a C program to find power of a number using for loop.
Write a C program to find all factors of a number.
Write a C program to calculate factorial of a number.
Write a C program to find HCF (GCD) of two numbers.
Write a C program to find LCM of two numbers.
Write a C program to check whether a number is Prime number or not.
Write a C program to print all Prime numbers between 1 to n.
Write a C program to find sum of all prime numbers between 1 to n.
Write a C program to find all prime factors of a number.
Write a C program to check whether a number is Armstrong number or not.
Write a C program to print all Armstrong numbers between 1 to n.
Write a C program to check whether a number is Perfect number or not.
Write a C program to print all Perfect numbers between 1 to n.
Write a C program to check whether a number is Strong number or not.
Write a C program to print all Strong numbers between 1 to n.
Write a C program to print Fibonacci series up to n terms.
Write a C program to find one's complement of a binary number.
Write a C program to find two's complement of a binary number.
Write a C program to convert Binary to Octal number system.
Write a C program to convert Binary to Decimal number system.
Write a C program to convert Binary to Hexadecimal number system.
Write a C program to convert Octal to Binary number system.
Write a C program to convert Octal to Decimal number system.
Write a C program to convert Octal to Hexadecimal number system.
Write a C program to convert Decimal to Binary number system.
Write a C program to convert Decimal to Octal number system.
Write a C program to convert Decimal to Hexadecimal number system.
Write a C program to convert Hexadecimal to Binary number system.
Write a C program to convert Hexadecimal to Octal number system.
Write a C program to convert Hexadecimal to Decimal number system.
Write a C program to print Pascal triangle upto n rows.
Star pattern programs - Write a C program to print the given star patterns.
Number pattern programs - Write a C program to print the given number patterns.

Functions

Write a C program to find cube of any number using function.


Write a C program to find diameter, circumference and area of circle using
functions.
Write a C program to find maximum and minimum between two numbers using functions.
Write a C program to check whether a number is even or odd using functions.
Write a C program to check whether a number is prime, Armstrong or perfect number
using functions.
Write a C program to find all prime numbers between given interval using functions.
Write a C program to print all strong numbers between given interval using
functions.
Write a C program to print all Armstrong numbers between given interval using
functions.
Write a C program to print all perfect numbers between given interval using
functions.
Write a C program to find power of any number using recursion.
Write a C program to print all natural numbers between 1 to n using recursion.
Write a C program to print all even or odd numbers in given range using recursion.
Write a C program to find sum of all natural numbers between 1 to n using
recursion.
Write a C program to find sum of all even or odd numbers in given range using
recursion.
Write a C program to find reverse of any number using recursion.
Write a C program to check whether a number is palindrome or not using recursion.
Write a C program to find sum of digits of a given number using recursion.
Write a C program to find factorial of any number using recursion.
Write a C program to generate nth Fibonacci term using recursion.
Write a C program to find GCD (HCF) of two numbers using recursion.
Write a C program to find LCM of two numbers using recursion.

Array exercises

Write a C program to display all array elements using recursion.


Write a C program to find sum of elements of array using recursion.
Write a C program to find maximum and minimum elements in array using recursion.
Write a C program to read and print elements of array. - using recursion.
Write a C program to print all negative elements in an array.
Write a C program to find sum of all array elements. - using recursion.
Write a C program to find maximum and minimum element in an array. - using
recursion.
Write a C program to find second largest element in an array.
Write a C program to count total number of even and odd elements in an array.
Write a C program to count total number of negative elements in an array.
Write a C program to copy all elements from an array to another array.
Write a C program to insert an element in an array.
Write a C program to delete an element from an array at specified position.
Write a C program to count frequency of each element in an array.
Write a C program to print all unique elements in the array.
Write a C program to count total number of duplicate elements in an array.
Write a C program to delete all duplicate elements from an array.
Write a C program to merge two array to third array.
Write a C program to find reverse of an array.
Write a C program to put even and odd elements of array in two separate array.
Write a C program to search an element in an array.
Write a C program to sort array elements in ascending or descending order.
Write a C program to sort even and odd elements of array separately.
Write a C program to left rotate an array.
Write a C program to right rotate an array.

List of matrix programming exercises


Write a C program to add two matrices.
Write a C program to subtract two matrices.
Write a C program to perform Scalar matrix multiplication.
Write a C program to multiply two matrices.
Write a C program to check whether two matrices are equal or not.
Write a C program to find sum of main diagonal elements of a matrix.
Write a C program to find sum of minor diagonal elements of a matrix.
Write a C program to find sum of each row and column of a matrix.
Write a C program to interchange diagonals of a matrix.
Write a C program to find upper triangular matrix.
Write a C program to find lower triangular matrix.
Write a C program to find sum of upper triangular matrix.
Write a C program to find sum of lower triangular matrix.
Write a C program to find transpose of a matrix.
Write a C program to find determinant of a matrix.
Write a C program to check Identity matrix.
Write a C program to check Sparse matrix.
Write a C program to check Symmetric matrix.
String exercises

Write a C program to find length of a string.


Write a C program to copy one string to another string.
Write a C program to concatenate two strings.
Write a C program to compare two strings.

Write a C program to convert lowercase string to uppercase.


Write a C program to convert uppercase string to lowercase.
Write a C program to toggle case of each character of a string.

Write a C program to find total number of alphabets, digits or special character in


a string.
Write a C program to count total number of vowels and consonants in a string.
Write a C program to count total number of words in a string.
Write a C program to find reverse of a string.
Write a C program to check whether a string is palindrome or not.
Write a C program to reverse order of words in a given string.
Write a C program to find first occurrence of a character in a given string.
Write a C program to find last occurrence of a character in a given string.
Write a C program to search all occurrences of a character in given string.
Write a C program to count occurrences of a character in given string.
Write a C program to find highest frequency character in a string.
Write a C program to find lowest frequency character in a string.
Write a C program to count frequency of each character in a string.
Write a C program to remove first occurrence of a character from string.
Write a C program to remove last occurrence of a character from string.
Write a C program to remove all occurrences of a character from string.
Write a C program to remove all repeated characters from a given string.
Write a C program to replace first occurrence of a character with another in a
string.
Write a C program to replace last occurrence of a character with another in a
string.
Write a C program to replace all occurrences of a character with another in a
string.
Write a C program to find first occurrence of a word in a given string.
Write a C program to find last occurrence of a word in a given string.
Write a C program to search all occurrences of a word in given string.
Write a C program to count occurrences of a word in a given string.
Write a C program to remove first occurrence of a word from string.
Write a C program to remove last occurrence of a word in given string.
Write a C program to remove all occurrence of a word in given string.
Write a C program to trim leading white space characters from given string.
Write a C program to trim trailing white space characters from given string.
Write a C program to trim both leading and trailing white space characters from
given string.
Write a C program to remove all extra blank spaces from given string.

TUTORIALS
EXAMPLES
REFERENCES
Popular Examples
C Examples

C Program to Create Pyramids and Patterns

C Examples

C Program to Check Prime Number

C Examples

C Program to Check Palindrome Number

C Examples

C Program to Print Hello World

All Examples
Introduction
Decision Making and Loops
Functions
Arrays and Pointers
Strings
Structures and Unions
File I/O

C "Hello, World!" Program


C Program to Print an Integer (Entered by the User)
C Program to Add Two Integers
C Program to Multiply Two Floating-Point Numbers
C Program to Find ASCII Value of a Character
C Program to Compute Quotient and Remainder
C Program to Find the Size of int, float, double and char
C Program to Demonstrate the Working of Keyword long
C Program to Swap Two Numbers
C Program to Check Whether a Number is Even or Odd
C Program to Check Whether a Character is a Vowel or Consonant
C Program to Find the Largest Number Among Three Numbers
C Program to Find the Roots of a Quadratic Equation
C Program to Check Leap Year
C Program to Check Whether a Number is Positive or Negative
C Program to Check Whether a Character is an Alphabet or not
C Program to Calculate the Sum of Natural Numbers
C Program to Find Factorial of a Number
C Program to Generate Multiplication Table
C Program to Display Fibonacci Sequence
C Program to Find GCD of two Numbers
C Program to Find LCM of two Numbers
C Program to Display Characters from A to Z Using Loop
C Program to Count Number of Digits in an Integer
C Program to Reverse a Number
C Program to Calculate the Power of a Number
C Program to Check Whether a Number is Palindrome or Not
C Program to Check Whether a Number is Prime or Not
C Program to Display Prime Numbers Between Two Intervals
C Program to Check Armstrong Number
C Program to Display Armstrong Number Between Two Intervals
C Program to Display Factors of a Number
C Programming Code To Create Pyramid and Structure
C Program to Make a Simple Calculator Using switch...case
C Program to Display Prime Numbers Between Intervals Using Function
C Program to Check Prime or Armstrong Number Using User-defined Function
C Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers
C Program to Find the Sum of Natural Numbers using Recursion
C Program to Find Factorial of a Number Using Recursion
C Program to Find G.C.D Using Recursion
C Program to Convert Binary Number to Decimal and vice-versa
C Program to Convert Octal Number to Decimal and vice-versa
C Program to Convert Binary Number to Octal and vice-versa
C program to Reverse a Sentence Using Recursion
C program to calculate the power using recursion
C Program to Calculate Average Using Arrays
C Program to Find Largest Element in an Array
C Program to Calculate Standard Deviation
C Program to Add Two Matrices Using Multi-dimensional Arrays
C Program to Multiply Two Matrices Using Multi-dimensional Arrays
C Program to Find Transpose of a Matrix
C Program to Multiply two Matrices by Passing Matrix to a Function
C Program to Access Array Elements Using Pointer
C Program Swap Numbers in Cyclic Order Using Call by Reference
C Program to Find Largest Number Using Dynamic Memory Allocation
C Program to Find the Frequency of Characters in a String
C Program to Count the Number of Vowels, Consonants and so on
C Program to Remove all Characters in a String Except Alphabets
C Program to Find the Length of a String
C Program to Concatenate Two Strings
C Program to Copy String Without Using strcpy()
C Program to Sort Elements in Lexicographical Order (Dictionary Order)
C Program to Store Information of a Student Using Structure
C Program to Add Two Distances (in inch-feet system) using Structures
C Program to Add Two Complex Numbers by Passing Structure to a Function
C Program to Calculate Difference Between Two Time Periods
C Program to Store Information of Students Using Structure

You might also like