Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

programming contest NR. godamind idk

Name: Anonymous 2010-05-22 15:01

So we didnt have one in a long time.

The assignment:

Write a program which can print all the characters in the word ´´Sussman'' in a random order, but none of the characters may appear more times then the word ´´Sussman'' contains.

GO!

Name: Anonymous 2010-05-22 20:07

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main(void) {
        char sussman[] = { 'S', 'u', 's', 's', 'm', 'a', 'n', '\0' };
        int n = strlen( sussman ) -1;

        srand( time( NULL ) );

        while (n) {
                int r = rand() % n;
                char temp = sussman[n];
                sussman[n] = sussman[r];
                sussman[r] = temp;
                --n;
        }

        printf("%s\n", sussman);
        return 0;
}

http://codepad.org/H7q6N4gy

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List