adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C and C++ to find HCF of two number using Division method

Program in C and C++ to find HCF of two number using Division method



C
#include<stdio.h>
#include<conio.h>
 int HCF(int a,int b)
  {
    int did,div,rem;
    if(a>b)
     {
        did=a;
        div=b;
     }
    else
     {
        did=b;
        div=a;
     }
    do{
        rem=did%div;
        if(rem!=0)
         {
            did=div;
            div=rem;
         }
      }while(rem!=0);
    return div;
  }
 int main()
  {

      int a,b,yes;
      start:
        printf("Enter two number :-");
        scanf("%d%d",&a,&b);
        printf("HCF = %d",HCF(a,b));
        printf("\nAgain calculate (1):- ");
        scanf("%d",&yes);
        if(yes==1)
         goto start;
      return 0;
  }
CPP
#include<iostream>
#include<conio.h>
 using namespace std;
 int HCF(int a,int b)
  {
    int did,div,rem;
    if(a>b)
     {
        did=a;
        div=b;
     }
    else
     {
        did=b;
        div=a;
     }
    do{
        rem=did%div;
        if(rem!=0)
         {
            did=div;
            div=rem;
         }
      }while(rem!=0);
    return div;
  }
 int main()
  {

      int a,b,yes;
      start:
        cout<<"Enter two number :-";
        cin>>a>>b;
        cout<<"HCF = "<<HCF(a,b);
        cout<<"\nAgain calculate (1):- ";
        cin>>yes;
        if(yes==1)
         goto start;
      return 0;
  }
Output :-





Related Programs
    

Post a Comment

0 Comments