Find GCD of Two Numbers Using While Loop in C

Mandalika
Updated on 05-Mar-2021 11:17:21

7K+ Views

ProblemGenerate the greatest common divisor for any two numbers using C programming language.SolutionLet the user enter any two numbers from the console. For those two numbers, let’s find the greatest common divisor.The GCD of two numbers is the largest number that exactly divides both of them without a remainder.The logic we use to find the GCD of two numbers is as follows −while(b!=0) //check for b=0 condition because in a/b ,b should not equal to zero    {       rem=a % b;       a=b;       b=rem;    } Print aProgram 1 Live Demo#include int main(){   ... Read More

Convert Digits to Word Format Using Switch Case in C

Mandalika
Updated on 05-Mar-2021 11:06:39

7K+ Views

ProblemIs it possible to convert the given one or two-digit numbers into English words by using the C Programming language?SolutionWe can easily convert the given two-digit number into English word format with the help of a switch case. Not only two digits, but any number can also convert into English like a statement in C.In this program, we will convert one or two-digit numbers into English word format.Example Live Demo#include int main(){    int no;    printf("enter any 1 or 2 digit number:");    scanf("%d", &no);    if(no=99) //finding out whether enter no is 2 digit or not       ... Read More

Find Largest and Smallest Number in a Series Using C

Mandalika
Updated on 05-Mar-2021 11:00:04

18K+ Views

ProblemLet the user enter four series of integers in the console, find out a number which is smallest and largest in a seriesSolutionTo calculate the small and large number, we use if conditions. The logic we use to find the largest and smallest number is −if(minno>q) //checking 1st and 2nd number    minno=q; else if(maxno&l;q)    maxno=q; if(minno>r) //checking 1st and 3rd number    minno=r;Program 1 Live Demo#include int main(){    int minno, maxno, p, q, r, s;    printf("enter any four numbers:");    scanf("%d%d%d%d", &p, &q, &r, &s);    minno=p;    maxno=p;    if(minno>q) //checking 1st and 2nd number   ... Read More

C Program for Time Conversions Using If and ElseIf Statements

Mandalika
Updated on 05-Mar-2021 10:54:51

1K+ Views

ProblemHow to convert the time from 24 hr format to 12 hr format using C Programming language?SolutionRead the time value from the user (at run time). It has to be converted into 12 hr format from 24 hr.AlgorithmStart: Step 1: Enter time in 24 hr format Step 2: check the condition       i. If(hour==0)          Print min      Ii. Elseif(hour

Print Stars in Diamond Pattern Using C Language

Mandalika
Updated on 05-Mar-2021 10:48:51

716 Views

Here, to print stars in diamond pattern, we are using nested for loops.The logic that we use to print stars in diamond pattern is shown below −//For upper half of the diamond the logic is: for (j = 1; j

Add Two Complex Numbers Using C

Mandalika
Updated on 05-Mar-2021 10:39:16

432 Views

ProblemHow to add two complex numbers which are entered at run time by the user using C program −SolutionA complex number is a number that can be a combination of real and imaginary parts.It is represented in the form of a+ib.ProgramFor example, let’s take the two complex numbers as (4+2i) and (5+3i) after adding the two complex numbers, the result is 9+5i. Live Demo#include struct complexNumber{    int realnumber, imaginarynumber; }; int main(){    struct complexNumber x, y, z, p;    printf("enter first complex number x and y");    scanf("%d%d", &x.realnumber, &x.imaginarynumber);    printf("enter second complex number z and p"); ... Read More

Print Integers in the Form of Pascal Triangle Using C

Mandalika
Updated on 05-Mar-2021 10:35:57

349 Views

Pascal's triangle is the representation of integers in the form of a triangle. One of the famous representations of it is with binomial equations. We can use combinations and factorials to achieve this.Constructing a Pascal triangleAll values outside the triangle are considered zero (0). The first row is 0 1 0 whereas only 1 acquire a space in Pascal’s triangle, 0s are invisible. The second row is acquired by adding (0+1) and (1+0). The output is sandwiched between two zeroes. The process continues till the required level is achieved.Programmatically, a Pascal triangle is defined as an array constructed by adding ... Read More

Print Floyd's Triangle of Integers Using C Program

Mandalika
Updated on 05-Mar-2021 10:31:09

233 Views

Floyd's triangle is a right-angle triangle of consecutive numbers, starting with a 1 in the top left corner −For example,1 2 3 4 5 6 7 8 9 10Example 1 Live Demo#include int main(){    int rows, i,j, start = 1;    printf("Enter no of rows of Floyd's triangle :");    scanf("%d", &rows);    for (i = 1; i

Check If a Number Is Armstrong Using C

Mandalika
Updated on 05-Mar-2021 10:27:39

10K+ Views

ProblemHow to check whether the given number is an Armstrong number or not using C Programming language?SolutionArmstrong number is the number that is equal to the sum of cubes of its digits.Syntaxpqrs………=pow(p, n)+pow(q, n)+pow(r, n)+……….For example, 153, 371, 1634, etc., are Armstrong numbers.153=1*1*1 + 5*5*5 + 3*3*3    =1+125+27    =153 (Armstrong number)Program Live Demo#include int main(){    int number, remainder, total=0, temp;    printf("enter the number=");    scanf("%d", &number);    temp=number;    while(number>0){       remainder=number%10;       total=total+(remainder*remainder*remainder);       number=number/10;    }    if(temp==total)       printf("This number is Armstrong number");    else   ... Read More

Print Given Number in Reverse Order Using Iterative Function in C

Mandalika
Updated on 05-Mar-2021 10:24:49

371 Views

ProblemHow to print the given in reverse order with the help of iterative function i.e., while loop using C programming language?SolutionSo far, we had seen how to reverse the string using string function and without string function, now let’s see how to reverse a number without using predefined function −AlgorithmInput − give a number at runtimeStep 1: Declare the variable number, reverse Step 2: Initialize reverse= 0 Step 3: while number>0         (a) reverse=reverse*10 + number%10;             reverse = reverse*10 + num%10;         (b) Divide number by 10 Step ... Read More

Advertisements