computing the GCD non-recursively

This is a discussion on computing the GCD non-recursively within the C Programming forums, part of the General Programming Boards category; Hello, I am working on this program that needs to compute the GCD non-recursively the programs has no errors but ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    11

    computing the GCD non-recursively

    Hello,

    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;
    }

    while(1)
    int c;
    {
    c = a%b;
    if(c==0)
    return b;
    a = b;
    b = c;
    }
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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
    Code:
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,505
    cross-posted there - http://www.daniweb.com/forums/thread149346.html
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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 Cprogramming.com
    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, 10:20 AM
  5. GCD For all of You!
    By Argentina in forum C Programming
    Replies: 0
    Last Post: 02-14-2002, 03:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21