C Programming Tutorial

 
 
 
 

Image

#include <stdio.h>
#include <conio.h>
#include <math.h>

int num1,num2,choice,temp1,temp2;

void lcm(){
      int i,lcm=1;
      num1 = temp1;
      num2 = temp2;
      printf(\"\\n\\nL.C.M OF NUMBER\\n\");
      while(num1>1 || num2>1){
        for(i=2;i<100;i++){
        if(num1%i==0 || num2%i==0){
        printf(\"\\n%4d | %4d ,  %4d\",i,num1,num2);
        if(num1%i==0){
            num1     = num1/i;
         }
        if(num2%i==0){
            num2     = num2/i;
        }
        lcm = lcm * i;
        }
          }
    }
    printf(\"\\nÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\");
    printf(\"\\n%4d | %4d ,  %4d\",lcm,1,1);
    printf(\"\\n\\nLCM IS %d\",lcm);
}

void gcf(){
      int i,gcfnum1=1,gcfnum2=1,cntnum1[100]={0},cntnum2[100]={0},gcf=1;
      num1 = temp1;
      num2 = temp2;
      printf(\"G.C.F. OF NUMBER\\n\");
      //For num1
      while(num1>1){
        for(i=2;i<100;i++){
        if(num1%i==0){
        printf(\"\\n%4d | %4d \",i,num1);
        num1     = num1/i;
        gcfnum1 = gcfnum1 * i;
        cntnum1[i]++;
        }
          }
    }
    printf(\"\\nÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\");
    printf(\"\\n%4d | %4d \",gcfnum1,1);
    printf(\"\\nGCF IS %d\",gcfnum1);
    printf(\"\\n%-4d  =  \",temp1);
    for(i=2;i<100;i++){
        if(cntnum1[i]>0)
           printf(\" (%3d^%-3d) \",i,cntnum1[i]);
    }


    //For num2
    printf(\"\\n\\n\");
    while(num2>1){
        for(i=2;i<100;i++){
        if(num2%i==0){
        printf(\"\\n%4d | %4d \",i,num2);
        num2     = num2/i;
        gcfnum2 = gcfnum2 * i;
        cntnum2[i]++;
        }
          }
    }
    printf(\"\\nÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\");
    printf(\"\\n%4d | %4d \",gcfnum2,1);
    printf(\"\\n\\nGCF IS %3d\",gcfnum2);
    printf(\"\\n%-4d  =  \",temp2);
    for(i=2;i<100;i++){
        if(cntnum2[i]>0)
           printf(\" (%3d^%-3d) \",i,cntnum2[i]);
    }

    //GCF logic
    for(i=2;i<100;i++){
         if(cntnum1[i]==0 || cntnum2[i]==0)
        continue;
         else if(cntnum1[i]<cntnum2[i])
        gcf = gcf * pow(i,cntnum1[i]);
         else if(cntnum2[i]<cntnum1[i])
        gcf = gcf * pow(i,cntnum2[i]);
         else if(cntnum1[i]>0)
        gcf = gcf * pow(i,cntnum1[i]);
         else if(cntnum2[i]>0)
        gcf = gcf * pow(i,cntnum2[i]);
    }

    printf(\"\\n\\nGCF of  %d  and  %d  is  %d\",temp1,temp2,gcf);
}

void main(){
    void lcm(void);
    void gcf(void);
    clrscr();
    printf(\"*****LCM And GCF of Given Numbers*****\");
    up:
    printf(\"\\n\\nEnter num1 : \");
    scanf(\"%d\",&num1);
    printf(\"Enter num2 : \");
    scanf(\"%d\",&num2);
    temp1 = num1;
    temp2 = num2;
    while(1){
    clrscr();
    printf(\"\\n\\nChoose your Choice\\n\");
    printf(\"1)  L.C.M\\n\");
    printf(\"2)  G.C.F\\n\");
    printf(\"3)  Scan New Numbers\\n\");
    printf(\"4)  Exit\\n\");
    printf(\"Enter your choice : \");
    scanf(\"%d\",&choice);
    switch(choice){
        case 1 : clrscr();
             lcm();
             break;
        case 2 : clrscr();
             gcf();
             break;
        case 3 : goto up;
        case 4 :
             exit(1);
        default: printf(\"\\n\\nINVALID CHOICE\\n\");
    }
       getch();
      }
}

    Related Post:
  1. PROGRAM FOR SUM OF ARRAY USING SPIN LOCK

  2. Program to find the length of a string taken from user without using strlen function

  3. Program to get substring

  4. Program to copy the contents of one array to another using shared memory

  5. Program to sort numbers in ascending order and use integer pointer to store numbers

  6. Program of expression Splitting using multiple barriers

  7. Program to read the Partition Table Information of Drive C using biosdisk( ) function

  8. Program reads 4 values a, b, c, and d and evaluates the ratio of (a+b) to (c-d) and prints the result, if c-d is not equal to zero using if statement

  9. Program to create processes using fork() and check orphan state

  10. Program that takes a number from user and calculates its logarithm value to the base 10 and e, exponentiation, sin value, cosine value and square root

  11. Program using structures/file to print name and age of the oldest and the youngest student in the class

  12. Program to print triangle in opposite pattern

  13. Program to print triangle inside square using * (stars)

  14. Program to display array values and address of an array using function and for loop

  15. program to read the price of an item in decimal form and print the output in paisa

  16. Program to print ASCII value of inputted character

  17. PLOTTING OF TWO FUNCTIONS

  18. PROGRAM TO CALCULATE 10% BONUS OF SALARY

  19. Program that takes person information like name, birth date etc and provides facility to sort on each attribute

  20. Program to show the System Configuration using biosequip( ) function

 
 
Didn't find what you were looking for? Find more on Program to find least common multiple and greatest common factor of 2 numbers