Found 1401 Articles for C

Sum of first N natural numbers which are divisible by X or Y

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

546 Views

Adding up all natural numbers up to n, that are divisible by X or Y is selecting all the numbers that are divisible by X or Y and adding them to a variable that stores the sum.To find the sum of the first N natural numbers which are divisible by X or Y, there are two methods −Using loops and conditional statementsUsing formulaMethod 1 − Using loops and conditional statementsThis method uses a loop that counts up to n numbers and selects numbers that are divisible by X or Y and adds them and save to a variables at each ... Read More

C Program to Add two Integers

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

845 Views

A program to add two numbers takes to numbers and does their mathematical sum and gives it to another variable that stores its sum.Example Code Live Demo#include int main(void) {    int a = 545;    int b = 123;    printf("The first number is %d and the second number is %d ", a , b);    int sum = a + b;    printf("The sum of two numbers is %d" , sum);    return 0; }OutputThe first number is 545 and the second number is 123 The sum of two numbers is 668

C Program for Program to find the area of a circle?

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

16K+ Views

The area is a quantity that represents the extent of the figure in two dimensions. The area of a circle is the area covered by the circle in a two dimensional plane.To find the area of a circle, the radius[r] or diameter[d](2* radius) is required.The formula used to calculate the area is (π*r2) or {(π*d2)/4}.Example CodeTo find the area of a circle using radius. Live Demo#include int main(void) {    float pie = 3.14;    int radius = 6;    printf("The radius of the circle is %d " , radius);    float area = (float)(pie* radius * radius);    printf("The ... Read More

Add 1 to a given number?

karthikeya Boyini
Updated on 30-Jun-2020 15:14:54

1K+ Views

A program to add 1 to a given number increments the value of the variable by 1 . This is general used in counters.There are 2 methods to increase that can be used to increase a given number by 1 −Simple adding of one to the number and reassigning it to the variable.Using increment operator in the program.Method 1 − using reassignment methodThis method takes the variable, add 1 to it and then reassigns its value.Example Code Live Demo#include int main(void) {    int n = 12;    printf("The initial value of number n is %d ", n);    n ... Read More

Average of first n even natural numbers?

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

604 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

430 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

108 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

186 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

467 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

262 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

Advertisements