Write a program using function to find factorial of a number

#include <stdio.h> // Function to calculate factorial int factorial(int n) { int fact = 1; for(int i = 1; i <= n; i++) { fact *= i; } return fact; } int main() { int num; printf(“Enter a positive integer: “); scanf(“%d”, &num); if(num < 0) { printf(“Factorial is not defined for negative numbers.\n”); } […]

Actual Arguments And Formal Arguments

Actual Arguments These are the real values or variables you pass to a function when calling it. They appear in the function call. int main() { int a = 10, b = 20; add(a, b); // a and b are actual arguments return 0; } Formal Arguments These are the placeholders or parameters defined in […]

C Program to find the reverse of a number

#include <stdio.h> int main() { int num, reversed = 0, remainder; // Input from user printf(“Enter an integer: “); scanf(“%d”, &num); while (num != 0) { remainder = num % 10; // Get the last digit reversed = reversed * 10 + remainder; // Build the reversed number num = num / 10; // Remove […]

Program to count the no of digits in a number

Counting the number of digits in a number is a common beginner-level program in C. This helps in understanding how to use loops and arithmetic operations like division. #include <stdio.h> int main() { int num, count = 0; // Input from user printf(“Enter a number: “); scanf(“%d”, &num); // Handle 0 separately if (num == […]

Program to check whether a given number is a palindrome or not

A number is called a palindrome if it reads the same backward as forward. Examples: 121, 1331, 454 are palindrome numbers. #include int main() { int num, original, reversed = 0, remainder; // Input from user printf(“Enter a number: “); scanf(“%d”, &num); original = num; // Store original number // Reverse the number while (num […]

Program to enter a grade & check its corresponding remarks

This program accepts a grade as input (like A, B, C, etc.) and displays the corresponding remark using conditional statements. This is a good practice for learning if-else or switch-case in C. #include <stdio.h> int main() { char grade; // Input from user printf(“Enter your grade (A, B, C, D, F): “); scanf(” %c”, &grade); […]

Write a program to check for the relation between 2 nos

#include <stdio.h> int main() { int num1, num2; // Input two numbers from user printf(“Enter first number: “); scanf(“%d”, &num1); printf(“Enter second number: “); scanf(“%d”, &num2); // Check and display the relationship if (num1 > num2) { printf(“%d is greater than %d\n”, num1, num2); } else if (num1 < num2) { printf(“%d is less than […]