Thread: simple rand() ques.

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    5

    simple rand() ques.

    Hi
    Please let me know why we are checking i%5 == 0 .Dont understand that bit .

    #include<stdio.h>
    main()
    {
    int i;
    for (i = 1 ;i <= 20 ;i++)
    {
    printf("%10d", 1 + (rand() % 6));

    if (i % 5 == 0)
    printf("\n");
    }
    }

    Thanks for your time and patience .

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: simple rand() ques.

    >Please let me know why we are checking i%5 == 0
    % is the modulos operator. It is used here to output a newline character after every 5 iterations of the loop.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM