I need to create a program
that does this v

A permutation is one of several possible ways in which you can order or arrange a group of things. Write a program that displays a new random permutation of the integers 0 to 9 at the request of its user. For example, the program’s output could be as follows:
1237894560
Another permutation? yes
65310974280
Another permutation? no
Bye!

Your program should prints how many 7 was printed when user type no.

I got only up to here

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

int main(void)
{
    char ch;
    srand(time(NULL));
    do{
    printf("%d\n", rand());
     if(i=7)

    printf("would you like to print again Yes OR No:");
       fflush(stdin);
       scanf("%c",&ch);
       printf("====>>>%c\n",ch);

      }while  ( ch=='Y' || ch=='y');

           printf("Bye!\n");

    return 0;

Help my solve this :)

Recommended Answers

All 2 Replies

Have you accomplished anything since you posted that question? If you have please post updated code so that we aren't looking at old obsolete code that bugs you have already fixed.

@OP
I am unsure of what you are asking, here is how I am seeing this problem, are you simply generating a series of 10 random numbers in the range of 0 - 10? In that case, I would simply do the following (it's in Java but seeming how Java ripped off alot from C, it's safe to assume there is equivalent or similar methods available)

package permutationjava;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
 *
 * @author PBJ
 */
public class PermutationJava {

    /**
     * @param args the command line arguments
     */
    private static Scanner console = new Scanner(System.in);
    public static void main(String[] args) {
        ArrayList<Integer> numbersList = new ArrayList<>();
        for(int i = 0; i < 10; i++){
            numbersList.add(i);
        }
        System.out.println("Print the array, y/N?");
        char ch = console.next().toLowerCase().charAt(0);
        while(ch == 'y'){
            System.out.println("Print the array, y/N?");
            Collections.shuffle(numbersList);
            numbersList.toArray();
            if(ch == 'y'){
                System.out.println(numbersList.subList(0, 9).toString());
                console.next();
            }else{
                System.out.println("no array for you");
            }
        }
    }
}

I am transposing this to C, as we speak so I can train my C skills as well =D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.