Thread: Error in C programming - Fault: Integer division by zero

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    2

    Error in C programming - Fault: Integer division by zero

    Can somebody help me please?

    What is the problem with this very simple source code of Euclid algorthm?

    #include <stdio.h>
    void main(void)
    {
    unsigned long a,b,r;
    unsigned long auxa, auxb;
    printf("Introduceti valoarea lui a: "); scanf("%ld", &a);
    printf("Introduceti valoarea lui b: "); scanf("%ld", &b);
    auxa=a;
    auxb=b;

    while(b!=a)
    {
    r=a%b;
    a=b;
    b=r;
    }
    printf("-----------------------------\n");
    printf("cmmdc(%ld, %ld)= %ld", auxa,auxb,a);
    }

    When I try to compile this code in Borland C++ 5.0 or even in Microsoft Visual Studio 2008 I receive this error message:

    "Unhandled exception at 0x00f5144b in test.exe: 0xC0000094: Integer division by zero." (in Visual Studio 2008) and it seems that the error is in that line I marked with bold!

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    It is simple concept that denominator cannot be zero in division

    by looking at your error ur denominator will be coming as zero

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,608
    I don't think that is too close to Euclid's algorithm as explained here.

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    2
    Thank you very much RockyMarrone!

    You are right! My mistake! I should write while(b!=0) instead of while(b!=a)!

    Now works fine! Thank you for helping me!

    Why you say that whiteflags! This C program works fine! What is wrong with it?

    Vlad

  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    U r most WELCOME vladanea

    Enjoy C/C++ Programming

  6. #6
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    main() is supposed to be an integer type, and needs a return statement.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM