Computer programming is like learning a new language, but instead of words and sentences, you're dealing with instructions and algorithms. As a Class 10 student, delving into the world of programming through C language can be both exciting and challenging. C programming lays the groundwork for understanding more complex programming languages and concepts that you might encounter in your academic and professional journey.
In your Class 10 computer science curriculum, you'll come across several essential C programs that serve as building blocks for understanding the language's fundamentals. Mastering these programs not only helps you score well in exams but also equips you with valuable problem-solving skills and lays a strong foundation for future programming endeavors.
In this article, we'll explore some of the essential C programs that you'll encounter in your Class 10 syllabus. Each program will be explained in simple terms, making it easier for you to grasp the concepts and apply them in your programming assignments and projects. Let's dive into the fascinating world of C programming and unlock the secrets of these essential codes!
Very Important C Programs(Turn on Desktop Mode for Better View)
1. Find the average of any two numbers given by the user:
#include <stdio.h> #include <conio.h> int main() { int a, b; float avg; printf("Enter first number: "); scanf("%d", &a); printf("Enter second number: "); scanf("%d", &b); avg = (a + b) / 2; printf("Average of %d and %d = %.2f", a, b, avg); return 0; }
2. Calculate the average of three numbers:
#include <stdio.h> #include <conio.h> int main() { int a, b, c; float avg; printf("Enter first number: "); scanf("%d", &a); printf("Enter second number: "); scanf("%d", &b); printf("Enter third number: "); scanf("%d", &c); avg = (a + b + c) / 3; printf("Average of %d, %d, and %d = %.2f", a, b, c, avg); return 0; }
3. Calculate the volume of a cylinder:
#include <stdio.h> #include <conio.h> #include <math.h> int main() { float radius, height, volume; const float pi = 3.14159; printf("Enter radius of the cylinder: "); scanf("%f", &radius); printf("Enter height of the cylinder: "); scanf("%f", &height); volume = pi * radius * radius * height; printf("Volume of the cylinder = %.2f", volume); return 0; }
4. Calculate distance travelled by a body:
#include <stdio.h> #include <conio.h> int main() { float velocity, time, distance; printf("Enter velocity of the body (m/s): "); scanf("%f", &velocity); printf("Enter time taken by the body (seconds): "); scanf("%f", &time); distance = velocity * time; printf("Distance travelled by the body = %.2f meters", distance); return 0; }
5. Calculate area of a circle:
#include <stdio.h> #include <conio.h> #include <math.h> int main() { float radius, area; const float pi = 3.14159; printf("Enter radius of the circle: "); scanf("%f", &radius); area = pi * radius * radius; printf("Area of the circle = %.2f square units", area); return 0; }
6. Calculate and print the volume of a box:
#include <stdio.h> #include <conio.h> int main() { float length, width, height, volume; printf("Enter length of the box: "); scanf("%f", &length); printf("Enter width of the box: "); scanf("%f", &width); printf("Enter height of the box: "); scanf("%f", &height); volume = length * width * height; printf("Volume of the box = %.2f cubic units", volume); return 0; }
7. Get radius of a circle and print its circumference:
#include <stdio.h> #include <conio.h> #include <math.h> int main() { float radius, circumference; const float pi = 3.14159; printf("Enter radius of the circle: "); scanf("%f", &radius); circumference = 2 * pi * radius; printf("Circumference of the circle = %.2f units", circumference); return 0; }
8. Calculate the area of four walls:
#include <stdio.h> #include <conio.h> int main() { float length, width, height, area; printf("Enter length of the room: "); scanf("%f", &length); printf("Enter width of the room: "); scanf("%f", &width); printf("Enter height of the room: "); scanf("%f", &height); area = 2 * height * (length + width); printf("Area of the four walls = %.2f square units", area); return 0; }
9. Calculate total surface area of a box:
#include <stdio.h> #include <conio.h> int main() { float length, width, height, surfaceArea; printf("Enter length of the box: "); scanf("%f", &length); printf("Enter width of the box: "); scanf("%f", &width); printf("Enter height of the box: "); scanf("%f", &height); surfaceArea = 2 * (length * width + length * height + width * height); printf("Total surface area of the box = %.2f square units", surfaceArea); return 0; }
10. Calculate and print the simple interest:
#include <stdio.h> #include <conio.h> int main() { float principal, rate, time, interest; printf("Enter principal amount: "); scanf("%f", &principal); printf("Enter rate of interest (per annum): "); scanf("%f", &rate); printf("Enter time period (in years): "); scanf("%f", &time); interest = (principal * rate * time) / 100; printf("Simple interest = %.2f", interest); return 0; }
11. Get temperature in Fahrenheit and convert to Celsius:
#include <stdio.h> #include <conio.h> int main() { float fahrenheit, celsius; printf("Enter temperature in Fahrenheit: "); scanf("%f", &fahrenheit); celsius = (fahrenheit - 32) * 5 / 9; printf("Temperature in Celsius = %.2f", celsius); return 0; }
12. Calculate the area of a triangle:
#include <stdio.h> #include <conio.h> int main() { float base, height, area; printf("Enter base of the triangle: "); scanf("%f", &base); printf("Enter height of the triangle: "); scanf("%f", &height); area = 0.5 * base * height; printf("Area of the triangle = %.2f square units", area); return 0; }
13. Get temperature in Fahrenheit and convert to Celsius:
#include <stdio.h> #include <conio.h> int main() { float fahrenheit, celsius; printf("Enter temperature in Fahrenheit: "); scanf("%f", &fahrenheit); celsius = (fahrenheit - 32) * 5 / 9; printf("Temperature in Celsius = %.2f", celsius); return 0; }
14. Convert USD (dollar) into Nepali Currency (NC):
#include <stdio.h> #include <conio.h> int main() { float usd, nc; printf("Enter amount in USD: "); scanf("%f", &usd); nc = usd * 118.71; // Assuming 1 USD = 118.71 NC (Nepali Currency) printf("%.2f USD is equal to %.2f NC", usd, nc); return 0; }
15. Convert Nepali Currency (NC) into Indian Currency (IC):
#include <stdio.h> #include <conio.h> int main() { float nc, ic; printf("Enter amount in Nepali Currency (NC): "); scanf("%f", &nc); ic = nc * 0.62; // Assuming 1 NC = 0.62 IC (Indian Currency) printf("%.2f NC is equal to %.2f IC", nc, ic); return 0; }
16. Display whether the given number is positive, negative, or zero:
#include <stdio.h> #include <conio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); if (num > 0) printf("%d is positive", num); else if (num < 0) printf("%d is negative", num); else printf("Number is zero"); return 0; }
17. Test whether the given number is divisible by 13 or not:
#include <stdio.h> #include <conio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); if (num % 13 == 0) printf("%d is divisible by 13", num); else printf("%d is not divisible by 13", num); return 0; }
18. Check whether the given number is divisible by 3 and 5 or not:
#include <stdio.h> #include <conio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); if (num % 3 == 0 && num % 5 == 0) printf("%d is divisible by both 3 and 5", num); else printf("%d is not divisible by both 3 and 5", num); return 0; }
19. Enter age and display whether a person can vote or not:
#include <stdio.h> #include <conio.h> int main() { int age; printf("Enter your age: "); scanf("%d", &age); if (age >= 18) printf("You are eligible to vote"); else printf("You are not eligible to vote"); return 0; }
20. Display the smaller among two numbers:
#include <stdio.h> #include <conio.h> int main() { int num1, num2; printf("Enter first number: "); scanf("%d", &num1); printf("Enter second number: "); scanf("%d", &num2); if (num1 < num2) printf("%d is smaller", num1); else if (num2 < num1) printf("%d is smaller", num2); else printf("Both numbers are equal"); return 0; }
21. Input three different numbers and find the greatest number:
#include <stdio.h> #include <conio.h> int main() { int num1, num2, num3; printf("Enter first number: "); scanf("%d", &num1); printf("Enter second number: "); scanf("%d", &num2); printf("Enter third number: "); scanf("%d", &num3); if (num1 >= num2 && num1 >= num3) printf("%d is the greatest", num1); else if (num2 >= num1 && num2 >= num3) printf("%d is the greatest", num2); else printf("%d is the greatest", num3); return 0; }
22. Display the middle number among three different numbers:
#include <stdio.h> #include <conio.h> int main() { int num1, num2, num3; printf("Enter first number: "); scanf("%d", &num1); printf("Enter second number: "); scanf("%d", &num2); printf("Enter third number: "); scanf("%d", &num3); if ((num1 >= num2 && num1 <= num3) || (num1 <= num2 && num1 >= num3)) printf("%d is the middle number", num1); else if ((num2 >= num1 && num2 <= num3) || (num2 <= num1 && num2 >= num3)) printf("%d is the middle number", num2); else printf("%d is the middle number", num3); return 0; }
23. Check whether the given number is positive, negative, or zero:
#include <stdio.h> #include <conio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); if (num > 0) printf("%d is positive", num); else if (num < 0) printf("%d is negative", num); else printf("Number is zero"); return 0; }
24. Check whether the given year is a leap year or not:
#include <stdio.h> #include <conio.h> int main() { int year; printf("Enter a year: "); scanf("%d", &year); if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) printf("%d is a leap year", year); else printf("%d is not a leap year", year); return 0; }
25. Check whether the given number is a perfect square or not:
#include <stdio.h> #include <conio.h> #include <math.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); int sqrtNum = sqrt(num); if (sqrtNum * sqrtNum == num) printf("%d is a perfect square", num); else printf("%d is not a perfect square", num); return 0; }
26. Print the series: 9, 7, 5, ... 1
#include <stdio.h> #include <conio.h> int main() { int i; for (i = 9; i >= 1; i -= 2) printf("%d ", i); return 0; }
27. Print the series: 1, 1, 2, 3, 5, 8, ... up to ten terms
#include <stdio.h> #include <conio.h> int main() { int i, n = 10, t1 = 1, t2 = 1, nextTerm; for (i = 1; i <= n; ++i) { printf("%d, ", t1); nextTerm = t1 + t2; t1 = t2; t2 = nextTerm; } return 0; }
28. Print natural numbers from 1 to 5:
#include <stdio.h> #include <conio.h> int main() { int i; for (i = 1; i <= 5; ++i) printf("%d ", i); return 0; }
29. Print the first ten odd numbers:
#include <stdio.h> #include <conio.h> int main() { int i, count = 0; for (i = 1; count < 10; i += 2) { printf("%d ", i); ++count; } return 0; }
30. Print the sum of digits of a given number:
#include <stdio.h> #include <conio.h> int main() { int num, digit, sum = 0; printf("Enter a number: "); scanf("%d", &num); while (num > 0) { digit = num % 10; sum += digit; num /= 10; } printf("Sum of digits = %d", sum); return 0; }
31. Display product of digits of a given number:
#include <stdio.h> #include <conio.h> int main() { int num, digit, product = 1; printf("Enter a number: "); scanf("%d", &num); while (num > 0) { digit = num % 10; product *= digit; num /= 10; } printf("Product of digits = %d", product); return 0; }
32. Reverse the given digits:
#include <stdio.h> #include <conio.h> int main() { int num, reversedNum = 0, remainder; printf("Enter a number: "); scanf("%d", &num); while (num != 0) { remainder = num % 10; reversedNum = reversedNum * 10 + remainder; num /= 10; } printf("Reversed number = %d", reversedNum); return 0; }
33. Print the multiplication table of any input number up to tenth terms:
#include <stdio.h> #include <conio.h> int main() { int num, i; printf("Enter a number: "); scanf("%d", &num); for (i = 1; i <= 10; ++i) printf("%d * %d = %d\n", num, i, num * i); return 0; }
34. Check whether the given number is prime or not:
#include <stdio.h> #include <conio.h> int main() { int num, i, isPrime = 1; // 1 indicates true, 0 indicates false printf("Enter a number: "); scanf("%d", &num); if (num <= 1) isPrime = 0; else { for (i = 2; i <= num / 2; ++i) { if (num % i == 0) { isPrime = 0; break; } } } if (isPrime) printf("%d is a prime number", num); else printf("%d is not a prime number", num); return 0; }
35. Check whether the given number is a palindrome or not:
#include <stdio.h> #include <conio.h> int main() { int num, reversedNum = 0, originalNum, remainder; printf("Enter a number: "); scanf("%d", &num); originalNum = num; while (num != 0) { remainder = num % 10; reversedNum = reversedNum * 10 + remainder; num /= 10; } if (originalNum == reversedNum) printf("%d is a palindrome number", originalNum); else printf("%d is not a palindrome number", originalNum); return 0; }
If you have any doubts, Please let me know