Thread: computing the GCD non-recursively

  1. #1
    Registered User
    Join Date
    Oct 2008

    computing the GCD non-recursively


    I am working on this program that needs to compute the GCD non-recursively the programs has no errors but when it says result is not initlized because of this it aborts.

    #include "stdafx.h"
    #include "stdio.h"

    int main (void)
    int a,b,c,r,result;
    printf("enter a value for a\n");
    scanf ("%d", &a);
    printf("enter a value for b\n");
    scanf ("%d", &b);
    printf("The result is %d\n",result);

    if (a < b)
    c = a;
    a = b;
    b = c;
    return 0;

    int c;
    c = a%b;
    return b;
    a = b;
    b = c;

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Well, it's not. Nowhere do you assign anything to result, so who knows what it is. Also, maybe you want to do the calculations before you do the printing. It looks like you're missing the line
    result = function_name(a, b)
    and the thing at the bottom is supposed to be a function and not inside main.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    cross-posted there -
    no code tags here
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Gcd on three numbers
    By Ideswa in forum C Programming
    Replies: 7
    Last Post: 03-19-2009, 01:57 PM
  2. Computing Degree Question
    By cjwenigma in forum A Brief History of
    Replies: 2
    Last Post: 09-17-2007, 01:06 PM
  3. small Distributed computing utilies
    By vinit in forum C Programming
    Replies: 2
    Last Post: 04-17-2006, 03:37 AM
  4. GCD as fast as possible!
    By fischerandom in forum C Programming
    Replies: 21
    Last Post: 11-22-2005, 11:20 AM
  5. GCD For all of You!
    By Argentina in forum C Programming
    Replies: 0
    Last Post: 02-14-2002, 04:38 PM