Found 1401 Articles for C

C Program for Armstrong Numbers

Sunidhi Bansal
Updated on 23-Sep-2019 12:00:35

467 Views

We are given a task where we have to check a number n entered by the user, whether it’s Armstrong or not.An Armstrong number is when the sum of all the digits power by the number of digits or we can say order of digits n, is same as the digit.So below is a simple representation how to find the Armstrong number −Formula −wxyz…. = pow(w, n) +pow(x, n) + pow(y, n) + pow(z, n) + …..AlgorithmSTART Step 1-> Declare a function to find the value after power operation on the number    int power(int a, int b)     ... Read More

C Program for Area And Perimeter Of Rectangle

Sunidhi Bansal
Updated on 23-Sep-2019 11:47:18

3K+ Views

Given a length and breadth of a rectangle we have to find its area and Perimeter.Rectangle is 2-D figure containing four sides and four angles of 90 degree each. All the sides of rectangle are not equal only the opposite sides of a rectangle are equal. The diagonals in a rectangle also are of the same length.Below is a diagrammatic representation of rectangle.Here A represents the breadth and B represents length of the rectangle.To find the Area of a rectangle the formula is: Length x BreadthAnd Perimeter of a rectangle is − 2 x (Length+Breadth).ExamplesInput: 20 30 Output: area of rectangle ... Read More

C Program for n-th odd number

Sunidhi Bansal
Updated on 23-Sep-2019 11:46:16

826 Views

Given a number N we have to find the N-th odd number.Odd numbers are the numbers which are not completely divided by 2 and their remainder is not zero. Like 1, 3, 5, 7, 9, ….If we closely observe the list of even numbers we can also represent them as(2*1)-1=1, (2*2)-1=3, ( 2*3)-1=5, (2*4)-1=7, ….(2*N)-1.So, to solve the problem we can simply multiply the number N with 2 and subtract 1 from the result, that makes up an odd number.ExamplesInput: 4 Output: 7 The 4th odd number is 1, 3, 5, 7.. Input: 10 Output: 19AlgorithmSTART    STEP 1 -> ... Read More

C Program for n-th even number

Sunidhi Bansal
Updated on 23-Sep-2019 11:39:33

471 Views

Given a number N we have to find the N-th even number.Even numbers are the numbers which are completely divided by 2 and their remainder is zero. Like 2, 4, 6, 8, 10, ….If we closely observe the list of even numbers we can also represent them as2*1=2, 2*2=4, 2*3=6, 2*4=8, ….2*N.So, to solve the problem we can simply multiply the number N with 2, so the result will be the number which is divisible by 2, i.e. the even number.ExampleInput: n = 4 Output: 8 The first 4 even numbers will be 2, 4, 6, 8, .. Input: ... Read More

Program to Convert Radian to Degree in C

Sunidhi Bansal
Updated on 23-Sep-2019 10:58:09

2K+ Views

If input is in radian convert it to degree else input will be in radian convert it to degree. There are formulas that can be used for this conversion.Radian is the standard unit for measuring angles whereas the complete angle of circle is divided into 360 degree. Also, radian is the smaller value as 1 degree = 180 radians.Conversion Formulas −degree = radian * (180/pi) where, pi=3.14 or 22/7ExampleInput-: radian = 9.0 Output-: degree is : 515.92357AlgorithmStart Step 1 -> define macro as #define pi 3.14 Step 2 -> declare function for converting radian to degree    double convert(double radian) ... Read More

C Program to Minimum and Maximum prime numbers in an array

Narendra Kumar
Updated on 23-Sep-2019 10:21:56

625 Views

Problem statementGiven an array of n positive integers. We have to find the prime number with minimum and maximum value.If the given array is −arr [] = {10, 4, 1, 12, 13, 7, 6, 2, 27, 33} then minimum prime number is 2 and maximum prime number is 13Algorithm1. Find maximum number from given number. Let us call it maxNumber 2. Generate prime numbers from 1 to maxNumber and store them in a dynamic array 3. Iterate input array and use dynamic array to find prime number with minimum and maximum valueExample#include #include #include #define SIZE(arr) (sizeof(arr) ... Read More

Program for Identity Matrix in C

Sunidhi Bansal
Updated on 23-Sep-2019 08:05:23

1K+ Views

Given a square matrix M[r][c] where ‘r’ is some number of rows and ‘c’ are columns such that r = c, we have to check that ‘M’ is identity matrix or not.Identity MatrixIdentity matrix is also known as Unit matrix of size nxn square matrix where diagonal elements will only have integer value one and non diagonal elements will only have integer value as 0Like in the given Example below −$$I1=\begin{bmatrix}1 \end{bmatrix}, \ I2=\begin{bmatrix}1 & 0 \0 & 1 \end{bmatrix}, \ I3=\begin{bmatrix}1 &0 & 0 \0 &1 & 0 \0 &0 &1 \end{bmatrix}, \In=\begin{bmatrix}1 &0 &0  &...&0 \0 &1 &0 ... Read More

Program to Convert Centimeter to Feet and Inches in C

Sunidhi Bansal
Updated on 23-Sep-2019 06:49:00

1K+ Views

Given with the length into centimeter as an input, the task is to convert the given length into feet and inchesWe can use length conversion formula for this −1 feet = 30.48 cm 1 inche = 2.54 cmExampleInput-: centimetre = 100 Output -: Length in meter = 3m    Length in Kilometer = 0.003kmAlgorithmStart Step 1 -> Declare function to perform conversion    double convert(int centimeter)       set double inch = 0.3937 * centimetre       set double feet = 0.0328 * centimetre       print inch and feet Step 2 -> In main()    Declare ... Read More

Program to check if a given year is leap year in C

Sunidhi Bansal
Updated on 23-Sep-2019 06:41:09

477 Views

Leap year has 366 days whereas a normal year has 365 days and the task is to check through the program whether the given year is a leap year or not.The logic for it can be through checking if year is divided by 400 or 4 but if the number is not divided by either of the number than it will be a normal year.ExampleInput-: year=2000 Output-: 2000 is a Leap Year Input-: year=101 Output-: 101 is not a Leap yearAlgorithmStart Step 1 -> declare function bool to check if year if a leap year or not bool check(int ... Read More

Program to calculate the value of nPr in C Program

Sunidhi Bansal
Updated on 23-Sep-2019 06:32:26

347 Views

Given with the n P r, where P represents Permutation, n represents total numbers and r represents arrangement the task is to calculate the value of nPr.Permutation is the arrangement of data in a sequence or order. Permutation and combination differs in the sense that permutation is the process of arranging whereas combination is the process of selection of elements from the given set.Formula for permutation is −nPr = (n!)/(n-r)!ExampleInput-: n=5 r=2 Output-: 20AlgorithmStart Step 1 -> declare function to calculate value of nPr    int cal_n(int n)       IF n Declare function to calculate the final ... Read More

Advertisements