Thread: Mod function not working

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    2

    Mod function not working

    Code:
    #include <stdio.h>
    
    
    int main()
    {
    	int m,c;
    	
    	for(c=0;c<100;c++)
    	{
    		m = c % 10;
    		printf("%d\t",m);
    	}
    	return(0);
    }
    When I run this code in my compiler, I get the first nine or ten numbers, and then after that it just spells out the letters in my name in different sequences over and over.

    Any thoughts?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Sorry, I cannot replicate your problem. Are you sure you compiled and ran this program, rather than say, a previous version of it?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2013
    Posts
    2
    Yeah, I just wrote this program and compiled it. It's strange because when I changed the code to c<10 and m=c%2, the program worked correctly.

  4. #4
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Well, I just tried in on Linux, FreeBSD and Windows and it works on all three (apart from having no \n at the end of the output so the cursor sits in a funny place after it's run)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. if function not working (its inside anot if function)
    By ahahsiol in forum C Programming
    Replies: 2
    Last Post: 03-08-2013, 08:55 AM
  2. gets(); function not working..
    By cloudpuffballz in forum C Programming
    Replies: 11
    Last Post: 11-02-2012, 03:31 AM
  3. Another function not working...
    By Inti in forum C Programming
    Replies: 4
    Last Post: 02-07-2009, 11:40 AM
  4. Function not working
    By Inti in forum C Programming
    Replies: 2
    Last Post: 02-07-2009, 09:48 AM
  5. why this function is not working
    By chintugavali in forum C++ Programming
    Replies: 6
    Last Post: 01-07-2008, 12:35 AM