CoolInterview.com - World's Largest Collection of Interview Questions
Start Your Own website Now
Sponsored Links

Interview Questions
Our Services

Get 9,000 Interview Questions & Answers in an eBook.


  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!



    Send your Resume to 6000 Companies


  • INTERVIEW QUESTIONS LANGUAGES C DETAILS
    Question :
    How to find GCD of four numbers?

    Posted by: vinayak on 3/29/2009

    Contact vinayak Contact vinayak
    Category C Interview Questions
    Rating (0.4) By 1035 users
    Added on 3/29/2009
    Views 1927
    Rate it!
    Answers:

    Take 4 numbers.The smallest number has to be found out.Then divide each number by that numbers which are less than that smallest number.
    e.g.5,15,75,20
    smallest-5
    so divide each numbers by 1,2,3,4,5.
    The GCD will be that number which divides all the number.(here 5)



    Posted by: prasenjit    

    Contact prasenjit Contact prasenjit

    Global coding data



    Posted by: saumya    

    Contact saumya Contact saumya

    #include<stdio.h>
    void main()
    {
    int a,b,c,d,i,gcd;
    printf("Enter Number 1");
    scanf("%d",a);
    printf("Enter Number 2");
    scanf("%d",b);
    printf("Enter Number 3");
    scanf("%d",c);
    printf("Enter Number 4");
    scanf("%d",d);
    for(i=1;i++;)
    {
    if((n%a==0)&&(n%b==0)&&(n%c==0)&&(n%d==0)
    {break;}
    )
    lcm = ((a*b*c*d)/i);
    }



    Posted by: Aj    

    Contact Aj Contact Aj

    #include<stdio.h>
    main()
    {
    int a,b,l;
    clrscr();
    printf("/nEnter nos:");
    scanf("%d%d",&a,&b);
    l=gcd(a,b);
    printf("GCD=%d",l);
    getch();
    }
    gcd(int a,int b)
    {
    int c=0;
    while(1)
    {
    c=a%b;
    if(c==0)
    return b;
    a=b;
    b=c;
    }
    }
    o/p:

    Enter nos:200 800
    GCD=200



    Posted by: AnuradhaSrikanth    

    Contact AnuradhaSrikanth Contact AnuradhaSrikanth

    #include<stdio.h>
    int main(void)
    {
    int a,b,c,d,i,r1,r2,r3,r4,lst,gcd;
    printf(" Enter The Numbers");
    scanf("%d %d %d %d", &a,&b,&c,&d);
    lst=a;
    if(b<lst)
    lst=b;
    if(c<lst)
    lst=c;
    if(c<lst)
    lst=d;
    for(i=2;i<=lst;i++)
    {
    r1=a%i;
    r2=b%i;
    r3=c%i;
    r4=d%i;
    if(r1==0 && r2==0 &&r3==0 && r4==0)
    gcd=i;
    else
    gcd=1;
    }
    printf("GCD=%d ", gcd);
    return 0;
    }

    one back log of this program is that you cant use negetive numbers



    Posted by: debdeep    

    Contact debdeep Contact debdeep

    #include<stdio.h>
    #include<conio.h>
    struct gcd
    {
    int n;
    int b[100][10];
    }k[4];
    void main()
    {
    int a=0,i=0,m=0,z=0,v=1;
    int j[4],l[4],x,y;
    clrscr();
    for(a=0;a<4;a++)
    {
    printf("Enter the value");
    scanf("%d",&k[a].n);
    m=k[a].n;
    j[a]=0;
    l[a]=0;
    for(i=2;i<=m;i++)
    {
    while(m%i==0)
    {
    m=m/i;
    k[a].b[l[a]][j[a]]=i;
    j[a]=j[a]+1;
    }
    j[a]=0;
    l[a]=l[a]+1;
    }
    printf(" ");
    }
    for(x=0;x<10;x++)
    {
    for(y=0;y<10;y++)
    {
    if(k[0].b[x][y]&&k[1].b[x][y]&&k[2].b[x][y]&&k[3].b[x][y])
    {
    printf(" common value are: %d",k[0].b[x][y]);
    v=v*k[0].b[x][y];
    }
    }
    }
    printf(" gcd value is: %d",v);
    getch();
    }



    Posted by: venkat    

    Contact venkat Contact venkat

    what is this?????????



    Posted by: man    

    Contact man Contact man

    1. First find out factors for the smallest number.
    2. Which factors of smallest number gives reminder zero when divisible each factor with each number.
    3. Take the common factors from four numbers and multiply them
    4.Then you get Gcd.




    ph no:+917842233607



    Posted by: rajasekharreddy.bhumireddy    

    Contact rajasekharreddy.bhumireddy Contact rajasekharreddy.bhumireddy

    If you have the better answer, then send it to us. We will display your answer after the approval.
    Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
  • Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
    Inform me about updated answers to this question

       
    Related Questions
    View Answer
    Write a program to accept any number up to six digit and print in words.
    for ex:1234=one two three four
    View Answer
    What is type integration? And what is integer type integration?
    View Answer
    What is :- Token , identifier , block , parameter , argument , scope of variable , Macro ?
    View Answer
    What is the code to find our age,for example if my date of birth is 4/12/1986 and today date is 16/11/2008
    answer should give our year,month,no of days
    View Answer
    What is the difference between unix and linux.
    View Answer
    How to convert decimal to octal and hexadecimal?
    View Answer
    If we want that any wildcard characters in the command line argument should be approxiemately expanded , are we required to make any special provision?if yes, which?
    View Answer
    How would you obtain the current time and difference between two times?
    View Answer
    What is a default TCP/IP socket assigned for SQL Server?
    View Answer
    #include <stdio.h>
    int main()
    {

    int a=3, b = 5;
    printf(&a["Ya!Hello! how is this? %s
    "], &b["junk/super"]);
    printf(&a["WHAT%c%c%c
    %c%c
    %c !
    "], 1["this"],
    2["beauty"],0["tool"],0["is"],3["sensitive"],4["CCCCCC"]);

    return 0;
    }
    View Answer
    How i can run *.bat or *.cmd file by using system function in c ?
    View Answer
    Why does a linker error occurs for the segment:
    main()
    {
    extern int i;
    i=20;
    printf("%d",sizeof(i));
    }
    View Answer
    Can there be a mouse click and drag function used together to rotate a circle in c?please give which are they?
    View Answer


    Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

    View ALL C Interview Questions

    User Options
    Sponsored Links


    Copyright ©2003-2014 CoolInterview.com, All Rights Reserved.
    Privacy Policy | Terms and Conditions

    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Dedicated Servers | C Interview Questions & Answers

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes


    Cache = 0.015625 Seconds