C Programming-Week 8 || Programming Assignment -1

Week-08 Program-01


C Programming-Week 8 || Programming Assignment -1

Q:- Write a C Program to find HCF of 4 given numbers using recursive function

#include<stdio.h>
int HCF(int, int); //You have to write this function which calculates the HCF. 
 
int main()
{
   int a, b, c, d, result;
   scanf("%d %d %d %d", &a, &b, &c, &d); /* Takes 4 number as input from the test data */
   result = HCF(HCF(a, b), HCF(c,d));
   printf("The HCF is %d", result);
return 0;
}

//Complete the rest of the program to calculate HCF

CODE:- 
*********************************************


int HCF(int x, int y)
{
  while(x!=y)
  {
    if(x>y)
    {
      return HCF(x-y,y);
    }
    
    else
    {
      return HCF(x,y-x);
    }
  }
  return x;
  
}

****************************************************

This Codes are 100% Tested and Working

No comments

Powered by Blogger.