I dont know what is wrong???

This is a discussion on I dont know what is wrong??? within the C Programming forums, part of the General Programming Boards category; hi guys , i have a problem with my code i dont know why the compiler did not work it ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    8

    I dont know what is wrong???

    hi guys , i have a problem with my code i dont know why the compiler did not work it it have no error before i run it but after it give me error noting in screen

    Code:
    /* This program finds an integer between 1 and 10000 that has       
    the largest number of divisors.  It prints out the maximum       
    number of divisors and an integer that has that many divisors.    */
    
    #include <stdio.h>
    void main()
    {
        int i ; 
    
    // One of the integers whose divisors we have to count.
    
     int max ; 
    
    // Maximum number of divisors seen so far.
    
    int nmax;
    
    // A value of N that had the given number of divisors.   
    
     max=1; 
    
    // Start with the fact that 1 has 1 divisor    
    
    nmax=1;
        
    
    /* Process all the remaining values of N from 2 to 10000, and           
    update the values of maxDivisors and numWithMax whenever we           
    find a value of N that has more divisors than the current value           
    of maxDivisors.        */  
    
      for(i=2;2<=10000;i++)
       {
           int j; 
    
    // A number to be tested to see if its a divisor of N.
    
    int ndivisor;
    
    // Number of divisors of N.
          
     for(j=1;j<=i;j++)
           {
               if(i%j==0)
                   ndivisor++;
    
    // Count the divisors of N.      
           }
           if(ndivisor>max)
           {
               max=ndivisor;
               nmax=i;
           }
        }
          printf("The maximum number of divisors is %d ",max);  
              printf("number of divisors it have is %d",nmax);
    }
    Last edited by Salem; 05-18-2012 at 02:19 AM. Reason: line wrapping

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Try setting ndivisor to 0 before you start counting.
    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.

  3. #3
    ZuK
    ZuK is online now
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Check the condition of the outher for loop.
    Kurt

  4. #4
    Registered User
    Join Date
    Mar 2012
    Posts
    8
    Quote Originally Posted by ZuK View Post
    Check the condition of the outher for loop.
    Kurt
    thanks very much it work now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dont know what im doing wrong... array
    By jamort in forum C++ Programming
    Replies: 6
    Last Post: 06-19-2009, 12:23 PM
  2. Replies: 13
    Last Post: 11-14-2008, 02:52 PM
  3. dont know whats wrong
    By otchster in forum C Programming
    Replies: 2
    Last Post: 11-02-2005, 10:14 AM
  4. i dont know what is wrong with it (help plz)
    By abuna in forum C++ Programming
    Replies: 16
    Last Post: 09-08-2005, 12:03 PM
  5. help......i dont understand what i am doing wrong?
    By Grifftt in forum C Programming
    Replies: 2
    Last Post: 10-18-2002, 11:37 PM

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