0% found this document useful (0 votes)
10 views

C Program Exercise Unit1 and Unit 2

This document contains 75 C program exercises that cover basic syntax and logic concepts including: printing patterns, number operations, if/else conditional statements, loops, functions, arrays, pointers, structures, unions, file handling and more. The exercises are grouped into categories like hello world programs, mathematical operations, pattern printing, number systems conversion, prime number programs and if/else conditional statements. The document provides practice problems for students to demonstrate their understanding of core C programming concepts.

Uploaded by

Sahil Dhapola
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

C Program Exercise Unit1 and Unit 2

This document contains 75 C program exercises that cover basic syntax and logic concepts including: printing patterns, number operations, if/else conditional statements, loops, functions, arrays, pointers, structures, unions, file handling and more. The exercises are grouped into categories like hello world programs, mathematical operations, pattern printing, number systems conversion, prime number programs and if/else conditional statements. The document provides practice problems for students to demonstrate their understanding of core C programming concepts.

Uploaded by

Sahil Dhapola
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

C Program Exercise: For Practice and Lab File

Submission Date: After Mid Semester Examination

1. WAP for hello world or this is my first C Program.


2. WAP to add two numbers.
3. WAP to find area of circle.
4. WAP to divide two numbers.
5. WAP to print ASCII value.
6. WAP to multiply floating point numbers.
7. WAP to SWAP two vairables number by using third variable.
8. WAP to SWAP two vairables number without using third variable.
9. WAP to SWAP three vairable numbers without using third variables.
10. Wap to find the area of rectangle.
11. WAP to find area of square
12. wap to find area of right angle triangle, isosceles triangle, any triangle with 3 sides.
13. wap to find Area and Volume of Cube.
14. wap to find area and volume of cuboid.
15. WAP to find the largest number using the Logical AND operator.
16. WAP to validate the username and password entered by the user is correct or not using
the predefined username and password.
17. WAP to input the positive number from the user to perform the Left shift operator.
18. WAP to input the positive number from the user to perform the Right shift operator.
19. WAP to perform the pre increment and pre decrement operator on two integers and
print both original value and updated value.
20. WAP to perform the post increment and post decrement operator on two integers and
print both original value and updated value.
21. WAP for an integer number and to check whether it is divisible by 9 or 7 using OR
logical operator.
22. WAP to identify gender in single character and print full gender (Ex: if input is 'M' or
'm' – it should print "Male").
23. Write a C program to print all natural numbers in reverse (from n to 1).
24. Write a C program to print all alphabets from a to z.
25. Write a CWrite a C program to print all natural numbers from 1 to n.
26. program to print all even numbers between 1 to 100.
27. Write a C program to print all odd number between 1 to 100.
28. Write a C program to find sum of all natural numbers between 1 to n.
29. Write a C program to find sum of all even numbers between 1 to n.
30. Write a C program to find sum of all odd numbers between 1 to n.
31. Write a C program to print multiplication table of any number.
32. Write a C program to count number of digits in a number.
33. Write a C program to find first and last digit of a number.
34. Write a C program to find sum of first and last digit of a number.
35. Write a C program to swap first and last digits of a number.
36. Write a C program to calculate sum of digits of a number.
37. Write a C program to calculate product of digits of a number.
38. Write a C program to enter a number and print its reverse.
39. Write a C program to check whether a number is palindrome or not.
40. Write a C program to find frequency of each digit in a given integer.
41. Write a C program to enter a number and print it in words.
42. Write a C program to print all ASCII character with their values.
43. Write a C program to find power of a number using for loop.
44. Write a C program to find all factors of a number.
45. Write a C program to calculate factorial of a number.
46. Write a C program to find HCF (GCD) of two numbers.
47. Write a C program to find LCM of two numbers.
48. Write a C program to check whether a number is Prime number or not.
49. Write a C program to print all Prime numbers between 1 to n.
50. Write a C program to find sum of all prime numbers between 1 to n.
51. Write a C program to find all prime factors of a number.
52. Write a C program to check whether a number is Armstrong number or not.
53. Write a C program to print all Armstrong numbers between 1 to n.
54. Write a C program to check whether a number is Perfect number or not.
55. Write a C program to print all Perfect numbers between 1 to n.
56. Write a C program to check whether a number is Strong number or not.
57. Write a C program to print all Strong numbers between 1 to n.
58. Write a C program to print Fibonacci series up to n terms.
59. Write a C program to find one's complement of a binary number.
60. Write a C program to find two's complement of a binary number.
61. Write a C program to convert Binary to Octal number system.
62. Write a C program to convert Binary to Decimal number system.
63. Write a C program to convert Binary to Hexadecimal number system.
64. Write a C program to convert Octal to Binary number system.
65. Write a C program to convert Octal to Decimal number system.
66. Write a C program to convert Octal to Hexadecimal number system.
67. Write a C program to convert Decimal to Binary number system.
68. Write a C program to convert Decimal to Octal number system.
69. Write a C program to convert Decimal to Hexadecimal number system.
70. Write a C program to convert Hexadecimal to Binary number system.
71. Write a C program to convert Hexadecimal to Octal number system.
72. Write a C program to convert Hexadecimal to Decimal number system.
Pattern Exercises
1. Star pattern programs - Write a C program to print the given star patterns.

*
***
*****
*******
*********

Pyramid Star Pattern

*
* *
* *
* *
*********

Hollow Pyramid Star Pattern

*********
*******
*****
***
*

Inverted Pyramid Star Pattern

*********
* *
* *
* *
*

Hollow Inverted Pyramid Star Pattern

*
**
***
****
*****
****
***
**
*
Half Diamond Star Pattern

*
**
***
****
*****
****
***
**
*
Mirrored Half Diamond Star Pattern

2. Number pattern programs - Write a C program to print the given number patterns

Square number patterns


11111
11111
11111
11111
11111

Number pattern 1
11111
00000
11111
00000
11111

Number pattern 2
01010
01010
01010
01010
01010

Number pattern 3
11111
10001
10001
10001
11111

Number pattern 4
11111
11111
11011
11111
11111

Number pattern 5
10101
01010
10101
01010
10101

If…Else Exercises
1. Write a C program to find maximum between two numbers.
2. Write a C program to find maximum between three numbers.
3. Write a C program to check whether a number is negative, positive or zero.
4. Write a C program to check whether a number is divisible by 5 and 11 or not.
5. Write a C program to check whether a number is even or odd.
6. Write a C program to check whether a year is leap year or not.
7. Write a C program to check whether a character is alphabet or not.
8. Write a C program to input any alphabet and check whether it is vowel or consonant.
9. Write a C program to input any character and check whether it is alphabet, digit or special
character.
10. Write a C program to check whether a character is uppercase or lowercase alphabet.
11. Write a C program to input week number and print week day.
12. Write a C program to input month number and print number of days in that month.
13. Write a C program to count total number of notes in given amount.
14. Write a C program to input month number and print number of days in that month.
15. Write a C program to count total number of notes in given amount.
16. Write a C program to input angles of a triangle and check whether triangle is valid or not.
17. Write a C program to input all sides of a triangle and check whether triangle is valid or not.
18. Write a C program to check whether the triangle is equilateral, isosceles or scalene triangle.
19. Write a C program to find all roots of a quadratic equation.
20. Write a C program to calculate profit or loss.
21. 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
22. 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%
23. 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
An additional surcharge of 20% is added to the bill

24. Write a C program to convert specified days into years, weeks and days.

#include <stdio.h>
int main()
{
int days, years, weeks;

days = 1329;
// Converts days to years, weeks and days
years = days/365;
weeks = (days % 365)/7;
days = days- ((years*365) + (weeks*7));

printf("Years: %d\n", years);


printf("Weeks: %d\n", weeks);
printf("Days: %d \n", days);

return 0;
}

You might also like