Category Archives: C Programs

C Programs

C program to find Sum of N Natural Numbers

C Program to find Sum of N Natural Numbers

In this tutorial, we will learn to create a C program that will find Sum of N Natural Numbers using C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

What is a Natural number?

The natural numbers are all those positive numbers from 1 to infinity. The set of natural numbers contains all whole positive numbers. The number with decimal points does not come under the natural numbers.

Algorithm:-

Program to find Sum of N Natural Numbers.

In this program, we will first take the point up to which we want to sum from zero to that point from the user. Then we will generate the series up to that point. At last, we will add those numbers will print the sum of n natural numbers.

With the help of this program, we can Find Sum of n natural numbers.

Program Code:-

Output:-

In the above program, we have first initialized the required variable.

  • n = it will hold the integer value.
  • i = it will hold the integer value.
  • sum = it will hold the integer value.

Input number from the user.

Program Logic Code.

Printing output.

C program to Reverse a Number

C Programs to Reverse any Number

In this tutorial, we will learn to create a C program that will reverse any Number using C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • While loop in C programming.
  • Conditional Statements in C programming.
  • Arithmetic operations in C Programming.

Program to reverse any number:-

In c programming, it is possible to take integer input from the user and reverse any Number with the help of a C program. The reversing of a number means the digits of a number will be swapped from the first position to the last position. The C language has many types of header libraries that have supported functions in them, with the help of these files the programming is easy.

With the help of this program, we can reverse any Number.

Algorithm:-

 

Program to reverse any number:-

Output:-

In the above program, we have first initialized the required variable.

  • n = it will hold the integer value.
  • remainder = it will hold the integer value.
  • rev = it will hold the integer value.

Input message for the user for the integer value.

Program Logic Code.

Printing output reverses any Number.

C Program to Print Even Numbers from 1 to N

C Program to Print Even Numbers from 1 to N

In this tutorial, we will learn to create a C program that will Print Even Numbers from 1 to N using C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

What is an Even number?

A number is said to be an even number when that number is divided by two into two equal whole numbers. And there should be a remainder of zero when it is being divided by 2.

Algorithm:

Program to Print Even Numbers from 1 to N.

In this program, we will first take the input point from the user. Then we will find the even numbers up to that range. At last, we will print that series of even numbers up to that number.

With the help of this program, we can print a series of Even numbers up to N number.

Program Code:-

 

Output:-

In the above program, we have first initialized the required variable.

  • i = it will hold the integer value.
  • no = it will hold the integer value of the input.

Input number from the user.

Program Logic Code.

Printing output.

C Program to print Odd Numbers from 1 to N

C Program to Print Odd Numbers from 1 to N

In this tutorial, we will learn to create a C program that will Print Odd Numbers from 1 to N using C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

What is an Odd number?

A number is said to be an Odd number when that number is divided by two into two equal whole numbers. And there should be a remainder of zero when it is being divided by 2.

Algorithm:

Program to Print Odd Numbers from 1 to N.

In this program, we will first take the input point from the user. Then we will find the Odd numbers up to that range. At last, we will print that series of Odd numbers up to that number.

With the help of this program, we can print a series of Odd numbers up to N number.

Program Code:-

Output:-

In the above program, we have first initialized the required variable.

  • i = it will hold the integer value.
  • no = it will hold the integer value of the input.

Input number from the user.

Program Logic Code to generate the series for odd numbers.

Printing output series.

C Program to find Sum of Odd Numbers from 1 to n

C Program to find Sum of Odd Numbers from 1 to n

In this tutorial, we will learn to create a C program that will find the sum of Odd Numbers from 1 to n using C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

What is an Odd number?

A number is said to be an Odd number when that number is divided by two into two, not equal whole numbers. And there should not be a remainder of zero when it is being divided by 2.

Program to find Sum of Odd numbers up to a range.

In this program, we will first take the input point from the user. Then we will find the Odd numbers up to that range and add them to a variable. At last, we will print that sum.

With the help of this program, we can Print Sum of Odd numbers.

Program to print the sum of Odd numbers to n Point:-

 

Output:-

In the above program, we have first initialized the required variable.

  • oddsum = it will hold the integer value for the sum of numbers.
  • i = it will hold the integer value.
  • no = it will hold the integer value of the input.

Input number from the user.

Program Logic Code.

Printing output sum of odd numbers.

C Program to find Sum of Even Numbers from 1 to n

C Program to find Sum of Even Numbers from 1 to n

In this tutorial, we will learn to create a C program that will find sum of Even Numbers from 1 to n using C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.
  • Arithmetic operations in C Programming.

What is an Even number?

A number is said to be an even number when that number is divided by two into two equal whole numbers. And there should be a remainder of zero when it is being divided by 2.

Program to find Sum of Even numbers up to a range.

In this program, we will first take the input point from the user. Then we will find the even numbers up to that range and add them to a variable. At last, we will print that sum.

With the help of this program, we can Print Sum of Even numbers.

Program to Print sum of Even numbers to n Point:-

 

Output:-

In the above program, we have first initialized the required variable.

  • evensum = it will hold the integer value for the sum of numbers.
  • i = it will hold the integer value.
  • no = it will hold the integer value of the input.

Input number from the user.

Program Logic Code.

Printing output sum.

C Program to find Square of a Number

C Program to find Square of a Number

In this tutorial, we will learn to create a C program that will find the square of a Number in C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • Arithmetic operations in C Programming.

What is a square of a number?

The Square of any number means a number multiplied by itself 2 times. This can also be called ‘a number squared’. The symbol for square is 2 {the power of any number is 2 for square}.

Algorithm:-

Program to Calculate the Square of a Number

In this program, we will take a number in input from the user. Then we will multiply that number by itself 2 times. After that, we will print the resultant answer to the user as an output.

With the help of this program, we can Square a number.

Output:-

In the above program, we have first initialized the required variable.

  • no = it will hold the integer value.
  • sq = it will hold the integer value.

Taking input number from the user to find the Square.

Calculating the Square of that number.

Printing output Square for that given number.

C program to Check Number is a Prime, Armstrong, or Perfect Number

C Program to Check Number is a Prime, Armstrong, or Perfect Number

In this tutorial, we will learn to create a C program that will check Number is a Prime, Armstrong, or Perfect Number in C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • While loop in C programming.

What is a prime number?

The prime numbers are those numbers that are only divisible by themselves. These numbers can’t be complete, divide by the 2 & 3.

What is an Armstrong number?

Armstrong number is a number that is equal to the sum of cubes of its digits.

What is a Perfect number?

A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself.

Algorithm:-

Program For checking the Number is a Prime, Armstrong, or Perfect Number:-

 

With the help of this program, we can check THE Number.

Program Code:-

Output:-

In the above program, we have first initialized the required variable.

  • num = it will hold the integer value.
  • i = it will hold the integer value.

Taking the input integer number from the user.

Checking the number is a prime number, Armstrong number, or perfect number.
Printing the output for the program.

 

C program to check Strong Number

C Program to check Strong Number

In this tutorial, we will learn to create a C program that will check Strong Number in C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • While loop in C programming.

What is a Strong number?

A strong number is a number whose sum of all digits’  “S” factorial is equal to the number N”. Let S be the sum of FACTORIAL of all the digits in a number is equal to its original number.

Algorithm:-

Program For checking a strong number:-

In today’s tutorial, we will take the input number from the user. Then we will Check the Number is strong number or not. At last, we will print the number is a strong number or not.

With the help of this program, we can check Strong Number.

Program Code:-

 

Output:-

In the above program, we have first initialized the required variable.

  • no = it will hold the integer value.
  • orgno = it will hold the integer value.
  • lastDigit = it will hold the integer value.
  • sum = it will hold the integer value.
  • fact = it will hold the float value.

Taking the input integer number from the user.

Checking the number is a strong number or not.
Printing the output for the program.

 

C Program to Convert Celsius to Fahrenheit

C Program to convert Celsius to Fahrenheit

In this tutorial, we will learn to create a C program that will convert Celsius to Fahrenheit in C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C Programming.
  • Arithmetic Operators in C Programming.

What are Celsius & Fahrenheit?

Celsius and Fahrenheit are the two most common scales to measure the temperature. Both the scales are having different values for the measurements of temperature. The formula for conversion is given below.

Algorithm:-

Program to convert Celsius to Fahrenheit.

In this program, we will first take the input from the user in Celsius. And then we will convert that input into Fahrenheit. Using the above table conversion formula and  Printing the result.

With the help of the below program, we can convert Celsius to Fahrenheit.

Program Code:-

Output:-

In the above program, we have first initialized the required variable.

  • Celsius and Fahrenheit = it will hold the temperature value.

Taking the input temperature from the user in Celsius.

Converting into Fahrenheit.

Printing the output of the program.

C Program to convert Fahrenheit to Celsius

C Program to convert Fahrenheit to Celsius

In this tutorial, we will learn to create a C program that will convert Fahrenheit to Celsius in C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C Programming.
  • Arithmetic Operators in C Programming.

What are Fahrenheit & Celsius?

Fahrenheit and Celsius are the two most common scales to measure the temperature. Both the scales are having different values for the measurements of temperature. The formula for conversion is given below.

Algorithm:-

Program to convert Fahrenheit to Celsius.

In this program, we will first take the input from the user in Fahrenheit. And then we will convert that input into Celsius. Using the above table conversion formula and  Printing the result.

With the help of the below program, we can convert Fahrenheit to Celsius.

Program Code:-

Output:-

In the above program, we have first initialized the required variable.

  • Fahrenheit = it will hold the temperature value.

Taking the input temperature from the user in Fahrenheit.

Converting into Celsius.

Printing the output of the program.

C Program to Convert Centimeter to Meter and Kilometer

C Program to convert Centimeter to Meter and Kilometer

In this tutorial, we will learn to create a C program that will convert Centimeter to Meter and Kilometer in C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C Programming.
  • Arithmetic Operators in C Programming.

What are Centimeter, Meter and Kilometer?

The Centimeter, Meter, and Kilometer are the metric units for the measurement of length between two points.

Description Table below.

Algorithm:-

Program to Convert Centimeters to meters and Kilometer.

In today’s program, we will first take the input from the user in centimeters. And then we will convert that input into meters, kilometers using a small program. Using the above table conversion values.

With the help of the below program, we can convert the centimeters to bigger units.

Program Code:-

Output:-

In the above program, we have first initialized the required variable.

  • cm = it will store the input centimeters value.

Taking the input from the user in centimeters.

Converting into bigger values.

Printing the output of the program.