C Programming Tutorial

Advertisements

Write program to display the lcd (lowest common divisior) of a given number in c



       #include<stdio.h>
       #include<conio.h>
       void main()
       {
              int num1,num2,i,lcd=1; 
              clrscr();

              printf("\nEnter 1st number : "); 
              scanf("%d",&num1);

              printf("\nEnter 2nd number : "); 
              scanf("%d",&num2);
              
              for(i=2;i<=num1 && i<=num2;i++)
              {
                     if(num1%i == 0  &&  num2%i==0)
                     {
                           lcd=i;
                           break;
                      }
              }
              
              printf("The lcd is : %d",lcd);

              getch();
       }

   Output : 

              Enter 1st number : 36
              Enter 2nd number : 72
              The lcd is : 2




Advertisement