C program to find greatest number from three numbers

Problem statement

Write a program to take three numbers as input from users and find a greatest numbers from three.
For example: Let three numbers are 34965, 34750, 34068
Then the greatest number is 34965.

Program to find greatest number

Output

Explanation

In above program first we take three numbers as input from users.
We are checking greatest number in three if statement.
To know the working of if-else statement check our post on if- else.

In first if we check number1 is greater than number2 and number3. If number1 is greater, then first if statement will execute and print ‘number1 is greater number’.
Otherwise corresponding else statement will execute.

In second else-if statement, we are checking number2 is greater than number1 and number3.
If condition is true then it print number2 is greater. Else the third else-if statement will execute.
In this way we will get greatest number from three numbers.

Note: If you dont know what is && and how it work then refer Operators.

Help others by sharing the content!

C program to find HCF

Problem statement

Write a program which takes two numbers as input from user and find the HCF of numbers.

What is HCF

HCF stands for Highest Common Factor(HCF).
HCF is also known as Greatest Common Measure(GCM) and Greatest Common Divisor(GCD)
HCF of two or more numbers is the greatest number which divides each of them exactly.
For example: HCF of 60 and 75 is 15.

C program to find HCF of two given numbers

Output

Help others by sharing the content!

C program to find ASCII value

Problem statement

Write a program to take character as input and find ASCII value of given character.

What is meant by ASCII value?

There are 256 different types of characters available in computers. Each character has their unique ASCII value.

The value range from 0 to 255. Out of the 256, first 128 are often called ASCII characters and the next 128 as Extended ASCII characters.
Most computers typically reserve 1 byte (8 bits) to represent a character in ASCII.

What is ASCII stands for?

ASCII stands for American Standard Code for Information Interchange.

Output

Program to find ASCII chart

Help others by sharing the content!

C program to find fibonacci series.

Problem statement

Write a program to take a number from user as an limit of a series and print Fibonacci series upto given input.

What is meant by Fibonacci series or sequence?

The Fibonacci sequence is a series where the next term is the sum of previous two terms. The first two terms of the Fibonaccii sequence is 0 followed by 1.

For example:

Here first two numbers 0 and 1 are same. Then 3rd term is an addition of 2nd and 1st term i.e. 0+1 = 1.
Then 4th term is an addition of 3rd and 2nd term i.e. 1+2 = 3. In this way, next term is sum of previous terms and we get Fibonacci series.

Output:

Fibonacci Series up to N number of terms

Output

Help others by sharing the content!

C program to find factorial of a number.

Problem statement

Write a program to take a number as an input from user and find the factorial of that number.

How to find factorial of a number

Factorial of a non-negetive number is denoted by n!.
Factorial of a number n is the product of all positive integers less than or equal to n.
For example:

Note: Factorial of a 0! = 1.

Output

C Program to find factorial of a number using recursion

What is recursion?

The process in which a function calls itself directly or indirectly is called recursion.
And this function is called as a recursion function.

Output

Help others by sharing the content!

C program to check Armstrong number?

Problem statement

Write a program to take a number as an input from user and check whether the input number is Armstrong number or not, and print the output accordingly.

What is meant by Armstrong number:

A number is called as Armstrong number if the sum of cubes of each digit is equal to the number itself.
For example:

Output:

C program to find given number is armstrong or not using loop

Output:

Explanation:

We take a input number 153 from user and store it into variable num.
We copy the value of num into orgnum so that we will do calculation on num and place orgnum as it is.
Now the while loop will execute up to num=0.
In first iteration:
153 != 0(true)
{
rem = num % 10; // rem = 153%10 = 3
num = num / 10; // num = 153/10 = 15
sum = sum+(rem*rem*rem);// sum = 0+(3*3*3) = 27
}
Second iteration
15 != 0(true)
{
rem = num % 10; // rem = 15%10 = 5
num = num / 10; // num = 15/10 = 1
sum = sum+(rem*rem*rem);// sum = 27+(5*5*5) = 27 + 125 = 152
}
Third iteration
1 != 0(true)
{
rem = num % 10; // rem = 1%10 = 1
num = num / 10; // num = 1/10 = 0
sum = sum+(rem*rem*rem);// sum = 152+(1*1*1) = 152 +1 = 153
}
Forth iteration
0 != 0(false)

These are the iterations of while loop, now the value of the sum is compared with the value of orgnum.
if sum == orgnum then it is Armstrong number and if not then it is not Armstrong number.
In our case, input number is Armstrong number.

Help others by sharing the content!