Find GCD or HCF of two numbers | User Given Number | C-Program

GCD or HCF:

Tips:

1.Take three variable.
2.Use conditional operator.
3.Use for loop for decrement the value.
4.Use if and break statement. 

Code:

#include<stdio.h>

void main()

{
    int a,b,c;

    printf("Enter two number:\n");

    scanf("%d%d",&a,&b);

    for(c=a>b?a:b;c>=1;c--)

        if(a%c==0 && b%c==0)

            break;

    printf("The GCD is %d\n",c);

getch();

}

Output:

Comments

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :