Write a program to find GCD of two numbers

The GCD or HCF (Highest Common Factor) of two integers is the greatest integer that divides both the integers with remainder equals to zero. This can be illustrated by Euclid’s remainder Algorithm which states that GCD of two numbers say x and y i.e. GCD(x, y) = x if y is 0 = GCD(y, x%y) […]

Write a program using recursion to find power of a number

We can write, nm = n*nm-1 =n*n*nm-2 =n*n*n*……………m times *nm-m The program which implements the above logic is as follows: #include<stdio.h> int power(int,int); void main() { int n,m,k; printf(“Enter the value of n and m”); scanf(“%d%d”,&n,&m); k=power(n,m); printf(“The value of nm for n=%d and m=%d is %d”,n,m,k); } int power(int x, int y) { if(y==0) […]

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 […]