Server Side Programming Articles - Page 2235 of 2650

Average of first n even natural numbers?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

1K+ Views

Average or mean of n even natural number is the sum of numbers divided by the numbers.You can calculate this by two methods &minusFind the sum of n even natural numbers and divide it by number, Using loop.Find the sum of n even natural numbers and divide it by number, Using formula.Method 1 - Using LoopFind the sum of even natural numbers using a loop that counts up to the number we want the sum. Then we will divide it by n.Example Code Live Demo#include int main(void) {    int n = 5;    int sum = 0;    int ... Read More

Program to calculate Area Of Octagon

Sharon Christine
Updated on 30-Jul-2019 22:30:26

865 Views

An octagon is a polygon with eight sides. To calculate the area of octagon the following formula is used, Area of octagon = ((a2*2) / *tan (22.5°)) = ((2*a*a)(1+√2))Code Logic, The area of a polygon with eight side is calculated by using the above formula. The expression uses sqrt function to find the square root of 2. The value of expression is evaluated as a floating point value that is put into the float area variable.Example Live Demo#include #include int main(){    int a = 7;    float area;    float multiplier = 6.18;    printf("Program to find area ... Read More

Program to calculate area of Enneagon

Sharon Christine
Updated on 30-Jul-2019 22:30:26

163 Views

An enneagon also known as nonagon is a polygon with 9 sides. To calculate the area of enneagon the following formula is used, Area of ennagon = ((a2*9) / 4*tan (20°)) ∼= (6.18 * a2)Code Logic, The area of a polygon with nine sides is calculated by using the formula, ((a2*9) / 4*tan (20°)) ∼= (6.18 * a2). The value 6.18 is filled into a float variable called multiplier, this value then multiplied by the square of side of enneagon.Example Live Demo#include #include int main(){    int a = 6;    float area;    float multiplier = 6.18;   ... Read More

Program to calculate area of Circumcircle of an Equilateral Triangle

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

243 Views

A circumcircle is a circle that inscribes a regular polygon inside it. The triangle that is inscribed inside a circle is an equilateral triangle. Area of circumcircle of can be found using the following formula, Area of circumcircle = “(a * a * (丌 / 3))”Code Logic, The area of circumcircle of an equilateral triangle is found using the mathematical formula (a*a*(丌/3)). The value of 丌 in this code is coded as 3.14. The expression is evaluated into a float value.Example Live Demo#include #include int main(){    int a = 5;    float area;    float pie = 3.14; ... Read More

Program to calculate the area of an Circle inscribed in a Square

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

714 Views

A circle inscribed in a square is a circle which touches the sides of the circle at its ends. I.e. the diameter of the inscribed circle is equal to the side of the square. The area can be calculated using the formula “((丌/4)*a*a)” where ‘a’ is the length of side of square.Logic of the Code - The area of circle inscribed inside the circle is calculated using the formula ((丌/4)*a*a) for this we need to define the value of pie (丌) that mathematically is 22/7 or 3.14. The expression that evaluates to the result is saved in a float variable.Example Live ... Read More

Program to calculate area and volume of a Tetrahedron

Sharon Christine
Updated on 30-Jul-2019 22:30:26

375 Views

A tetrahedron is a pyramid with triangular base i.e. it has a base that is a triangle and each side has a triangle. All the three triangles converge to a point. As in the figure, Code Logic − The code to find the area and volume of tetrahedron uses the math library to find the square and square-root of a number using sqrt and pow methods. For calculating the area we take a floating point and the value of the expression “((sqrt(3)*a*a))” is given to it. Another variable get the value of volume of the tetrahedron that is evaluated by ... Read More

Program to calculate area and perimeter of Trapezium

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

608 Views

Trapezium is a type of quadrilateral that has at least one pair of side parallel to each other. Area and perimeter of a trapezium can be found using the below formula, Perimeter = sum of all sidesArea = ½ x (sum of the lengths of the parallel sides) x perpendicular distance between parallel sidesCode logic − The code will use 5 variables in as all sides of trapezium and one for the perpendicular distance between the two parallel side. For the area variable calculation we will take a float variable that will be initialised with the value. To calculate it ... Read More

Program to calculate area and perimeter of equilateral triangle

Sharon Christine
Updated on 30-Jul-2019 22:30:26

502 Views

Tringle is a closed figure with three sides. An equilateral triangle has all sides equal. Area and perimeter of an equilateral triangle can be found using the below formula, Area of equilateral triangle = (√3)/4*a2Perimeter of equilateral triangle = 3 * aLogic of CodeTo find the area of an equilateral triangle program uses square-root and power functions. The math library has both these functions and can be used to do the calculation in the program.The below code display program to calculate the area and perimeter of an equilateral triangle, Example Live Demo#include #include int main(){    int side = ... Read More

Program to find the perimeter of a rhombus using diagonals

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

286 Views

Rhombus is a simple quadrilateral whose four sides all have the same length. And perimeter of rhombus can be found by two methods.Adding all side.Using the diagonalsA quadrilateral has two diagonal and based on the length of diagonals the area and perimeter of the quadrilateral can be found.To find the perimeter of a rhombus using its diagonals is 2{√(d1)2 + (d2)2 }LOGIC − To find the perimeter of a rhombus using its diagonals. You need the formula 2{√(d1)2 + (d2)2 } for this in your code you need to use the math class that supports the use of squareRoot and ... Read More

*args and **kwargs in Python

Sarika Singh
Updated on 04-Apr-2023 11:40:53

575 Views

When we define a function in a python program, the purpose is to execute the code again and again by supplying different values to the function's arguments. One challenge in this design is, what if we are not sure about the number of arguments we want to process each time we call that function. This is where the special arguments called **args and **kwargs are needed. Let's look at them one by one.*argsThe *args enables us to use variable number of arguments as input to the function. In the below example we are finding out the result of multiplication of ... Read More

Advertisements