Category Archives: C Programs

C Programs

C Program to Find Volume and Surface Area of a Cone

C Program to Find Volume and Surface Area of a Cone

In this tutorial, we will learn to create a C program that will Find the Volume and Surface Area of a Cone 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.
  • Mathematical operations in C programming.

Algorithm:-

Program description:-

In today’s tutorial, we will create a program, that will calculate the Volume and Surface Area of a Cone using C programming. First, take the input radius and the height of the cone from the user. Then we will find the surface Area and the volume of a cone using the mathematical functions and calculations in the c programming language. At last, we will print the Volume and Surface Area of a cone.

Program Code:-

Output:-

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

  •  rd = it will hold the integer value for the input radius of the cone.
  •  ht = it will hold the integer value for the input height of the cone.
  •  vm = it will hold the value of the volume of the cone.

Taking Input the radius and height of the cone from the user.

Calculating the surface area & volume of the cone.

Printing the volume and surface area of the cone.

C Program to Find Area of a Triangle

C Program to Find Area of a Triangle

In this tutorial, we will learn to create a C program that will Find the Area of a Triangle 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.
  • Mathematical operations in C programming.

Algorithm:-

Program description:-

In today’s tutorial, we will create a program, that will calculate the area of a triangle using C programming. First, take the input three sides of the triangle by the user. Then we will calculate the area of that triangle using the mathematical expression. At last, we will print the area of a triangle.

Program Code:-

Output:-

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

 

  •  x = it will hold the integer value for the input side of the triangle.
  •  y = it will hold the integer value for the input side of the triangle.
  •  z = it will hold the integer value for the input side of the triangle.
  • area = it will hold the area of the triangle.

Taking Input the three sides length the triangle.

Code to calculate the area of the triangle.

Printing output the area of the triangle.

C Program to Find the Area of a Circle

 

C Program to Find Area of a Circle

In this tutorial, we will learn to create a C program that will Find the Area of a Circle 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.
  • Mathematical operations in C programming.

Algorithm:-

Program description:-

In today’s tutorial, we will create a program, that will calculate the Area of a Circle using C programming. First, take the input radius of the circle from the user. Then we will calculate the  Area of a Circle using the mathematical expressions in the c programming language. At last, we will print the Area of a Circle.

Program Code:-

Output:-

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

 

  •  rad = it will hold the integer value for the input radius of the circle.
  •  ar = it will hold the value of the area of the circle.

Taking Input the radius of the circle from the user.

Defining the functions for the program.

Calling the user-defined functions.

Body of the user-defined functions for the calculations.

Printing the Area of a Circle.

C Program to Find Diameter, Circumference, and Area of a Circle

 

C Program to Find Diameter, Circumference, and Area of a Circle

In this tutorial, we will learn to create a C program that will Find the Diameter, Circumference, and Area of a Circle 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.
  • Mathematical operations in C programming.

Algorithm:-

Program description:-

In today’s tutorial, we will create a program, that will calculate the Diameter, Circumference, and Area of a Circle using C programming. First, take the input radius of the circle from the user. Then we will calculate the Diameter, Circumference, and Area of a Circle using the mathematical expressions in the c programming language. At last, we will print the Diameter, Circumference, and Area of a Circle.

Program Code:-

Output:-

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

  •  rad = it will hold the integer value for the input radius of the circle.
  •  ar = it will hold the value of the area of the circle.
  •  cm = it will hold the value of the area of the circle.
  •  dm = it will hold the value of the area of the circle.

Taking Input the radius of the circle from the user.

Defining the functions for the program.

Calling the user-defined functions.

Body of the user-defined functions for the calculations.

Printing the Diameter, Circumference, and Area of a Circle.

C Program to Print Reversed Mirrored Right Triangle

C Program to Print Reversed Mirrored Right Triangle Star Pattern

In this tutorial, we will learn to create a C program that will print a Reversed Mirrored Right Triangle Pattern 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.
  • For loop in C programming.
  • Conditional Statements in C programming.

Algorithm:-

With the help of this program, we will draw the pattern.

Program description:-

Mirrored patterns are just flipped patterns. In this program, we will first take the input number of rows by the user. Then we will use the input number of rows with the for loop and the conditional statements to draw the Reversed Mirrored Right Triangle pattern using the C programming language.

Below is the example program for the mirrored right triangle.

Program Code:-

Output:-

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

  • rw = it will hold the integer value for the input.
  • i = it will hold the integer value for the master loop.
  • j = it will hold the integer value for the slave loop.

Input the number of rows for the Reversed Mirrored Right Triangle Star.

Making the pattern using the for loops and conditional statements.

Printing output triangle using for loop and the confitional statements.

C Program to Find Area of a Right Angled Triangle

C Program to Find Area of a Right Angled Triangle

In this tutorial, we will learn to create a C program that will Find the Area of a Right Angled Triangle 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.
  • Conditional Statements in C programming.

Algorithm:-

Program description:-

In today’s tutorial, we will create a program, that will calculate the area of a right-angled triangle using C programming. First, take the input width, height of the right-angled triangle by the user. Then we will calculate the area of that right-angled triangle using the mathematical expression. At last, we will print the area of a right-angled triangle.

Program Code:-

Output:-

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

 

  • width = it will hold the integer value for the input width of the right-angled triangle.
  • height = it will hold the integer value for the input height of the right-angled triangle.
  • Area  = it will hold the integer value for the area of a right-angled triangle.
  • Perimeter = it will hold the integer value for the perimeter of a right-angled triangle.

Input the height, width of the right-angled triangle.

Code to calculate the area of the right-angled triangle.

Printing output the area of the right-angled triangle.

C Program to Find Find Area of an Equilateral Triangle

C Program to Find Area of an Equilateral Triangle

In this tutorial, we will learn to create a C program that will Find the Area of an Equilateral Triangle 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.
  • Conditional Statements in C programming.

What is an Equilateral triangle?

In an equilateral triangle, all the sides are of the same length. All the angles of the equilateral triangle are 60 degrees.

Algorithm:-

Program description that will print the area of an equilateral Triangle:-

In today’s tutorial, we will create a program, that will calculate the area of an equilateral triangle using C programming. First, take the input size of the side of the equilateral triangle by the user. Then we will calculate the area of that triangle using the mathematical expression. At last, we will print the area of an equilateral triangle.

Program Code:-

Output:-

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

 

  • length = it will hold the integer value for the input size of the side for the triangle.
  • ar  = it will hold the integer value for the area of a triangle.
  • pr = it will hold the integer value for the perimeter of a triangle.
  • sm  = it will hold the integer value for the semi perimeter of a triangle.

Input the size of the side of the triangle.

Code to calculate the area of the triangle.

Printing output the area of an equilateral triangle.

C program to find Profit or Loss

C program to find Profit or Loss

In this tutorial, we will learn to create a C program that will find Profit or Loss 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.
  • Conditional Statements in c programming.

What is the Profit or Loss?

The profit means the extra amount received from the buyer for the product, rather than that of its actual price. If the product is sold at the price below the cost price, then it will be taken as a loss in that product.

Algorithm:-

Program to find Profit or Loss.

In this program, we will first take the cost price and the selling price from the user. After taking the input, we will find whether the cost price is equal, greater, or lesser than the selling price. Now we will use the required functions to calculate the profit/loss for the product. At last, we will print the output to the user using the printf(); function.

Below is an example of profit-loss calculation.

With the help of this program, we can find Profit or Loss.

Program Code:-

Output:-

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

  • cp  = it will hold the input value of the cost price.
  • sp  = it will hold the input value of the cost price.

Taking the input cost price and the selling price from the user.

In this section of the code of the program, we will calculate the profit and the loss for the user.

Printing the roots of the given numbers by the user.

C Program to Calculate Standard Deviation

C Program to Calculate Standard Deviation

In this tutorial, we will learn to create a C program that will Calculate Standard Deviation 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.
  • Conditional Statements in c programming.
  • User-defined functions in C programming.

Algorithm:-

Program to Calculate Standard Deviation.

In this program, we will first take the five elements from the user. After taking the input, we will add all the elements. Then we will find its standard deviation, using the mathematical expression, and then we will print the standard deviation of five elements.

With the help of this program, we can Calculate Standard Deviation.

Program Code:-

Output:-

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

  • i = it will hold the integer value of the loop.
  • arry[5] = it will hold the integer value.

Taking the input elements of the array.

In this section of the code of the program, we will calculate the SD of the numbers.

Printing the standard deviation of the numbers.

C Program to find Student Grade

C Program to find Student Grade

In this tutorial, we will learn to create a C program that will find the Student Grade 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.
  • Conditional Statements in c programming.

Algorithm:-

Program to find Student Grade.

In this program, we will first take the marks of five subjects from the user. After taking the input, we will add all the marks and divide them by 5″ to get the percentage of the marks. Then we will print the grade of the students using the conditional statements.

Below is an example of the total, percentage, and grade.

With the help of this program, we can find the grade of the student.

Program Code:-

 

Output:-

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

  • EN, CH, CM, PH, MT = it will hold the input value of the numbers.
  • TOT = it will hold the float value for the total marks.
  • PER = it will hold the float value for the percentage.

Taking the input marks of the five subjects.

In this section of the code of the program, we will calculate the total of the marks and the percentage.

Printing the grade of the student according to the percentage.

C Program to find Roots of a Quadratic Equation

C Program to find Roots of a Quadratic Equation

In this tutorial, we will learn to create a C program that will find the Roots of a Quadratic Equation 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.
  • Conditional Statements in c programming.

What is a quadratic expression?

A quadratic equation is an algebraic expression of the second degree in x. The quadratic equation in its standard form is ax2 + bx + c = 0,
where a, b are the coefficients, x is the variable, and c is the constant term.

Algorithm:-

Program to find Roots of a Quadratic Equation.

In this program, we will first take the quadratic equation in input from the user for finding the roots. After taking the input, we will find the root of all three numbers using the mathematical expressions. Then we will print the output roots of the program using the “printf() ” function.

Below is an example of quadratic equations.

With the help of this program, we can check find Roots of a Quadratic Equation.

Program Code:-

 

Output:-

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

  • a, b, c = it will hold the input value of the number.
  • root1, root2, root3 = it will hold the root values for the numbers.

Taking the input numbers from the user for the quadratic equations.

In this section of the code of the program, we will find the roots for the numbers from the input.

Printing the roots of the given numbers by the user.

C Program for Positive or Negative Number

C Program for Positive or Negative Number

In this tutorial, we will learn to create a C program that will check the number is Positive or Negative Numbers 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.
  • Conditional Statements in c programming.

Algorithm:-

Program for Positive or Negative Number.

In this program, we will first take the input number from the user to check. After taking the input, we will use that number in conditional statements to check. Then we will print the output of the program using the “printf() ”  function. Whether it’s a positive, negative, or zero value.

With the help of this program, we can check Positive or Negative Numbers.

Program Code:-

 

Output:-

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

  • n = it will hold the integer input value of the number.

Taking the input number from the user in the integer format.

In this section of code for the program to check, a number is a positive number or a negative number, or a Zero.

Printing the output for the program after checking the conditions.