# Basic C Program Examples

##### C program to find area of triangle given 3 sides This Program accepts the three sides of the triangle a, b, c. Then, Calculates the Perimeter of the Triangle. Moreover, calculates the semi perimeter using the formula (a + b + c) / 2 and the Area of a triangle using Heron’s Formula: √(s × (s - a) × (s - b) × (s - c)). After the successful execution of the program the final area of a triangle is shown on screen.

##### C Program to Find the Area of Parallelogram This program first takes length of base and height form user using scanf () function and stores it in three floating point variables. Then it calculates the area of Parallelogram using the formula Area of parallelogram = base X height. Then, it prints the area of parallelogram on screen using printf () function.

##### C Program to Find the Area of Rhombus Above program first takes length of diagonals as input form user using scanf function and stores it in two floating point variables. Then it calculates the area of Rhombus using the formula given above. Then, it prints the area of Rhombus on screen using printf function.

##### C Program to Find the Area of Trapezium This program first takes length of parallel sides and height as input form user using scanf function and stores it in three floating point variables. Then it calculates the area of trapezium using the formula given above. Then, it prints the area of trapezoid on screen using printf function.

##### C Program to find factorial of a Number using Recursion Program execution will start from the beginning of the main() function. The main function consists of fact() recursive function, this fact() function is called from main() function with user entered number n as an argument. After passing number 5 to the fact() function will call fact() function (recursive call). In recursive call, the value of that passed argument ‘n’ is decreased by 1 until n value reaches less than 1. The fact(0) will always 1. Once n value is less than one, there is no recursive call and the factorial program will calculate and print output. Your C compiler asks you to enter a number to find factorial as follows:Enter a positive number: 5After you enter your number, the program will be executed and give output like below:Factorial of 5 = 120

##### C Program to find Power of a Number using Recursion In this Program, we will solve this problem using recursion. We will first take base and exponent as input from user and pass it to a recursive function, which will return the value of base raised to the power of exponent(base^exponent).

##### C Program to Find the Sum of First N Natural Numbers ##### C Program to Generate Fibonacci Series using recursion This Program adds previous two numbers value to compute the next number value. In this program Fibonacci series is calculated using recursion, with seed as 0 and 1. In the code Fibonacci function calls itself with a lesser value several times. An termination condition is very important to recursion function, i.e. n == 0 and n == 1 or the recursive call would be infinite leading to stack overflow error.

##### C Program to Generate Fibonacci Series In this Program, The first two elements are respectively started from 0 , 1, and the other numbers in the series are generated by adding the last two numbers of the series using looping. These numbers are stored in an array and printed as output.

##### C Program to Calculate Simple Interest This C program allows the user to enter the Principal Amount, Rate of Interest, and the Number of years. By using those values, this C Program will calculate the Simple Interest using following formula: Simple Interest = (Principal Amount * Rate of Interest * Number of years) / 100.

## Write For Us.

Contribute the Community.