mercredi 5 juin 2019

Array of integers of 1s and 0s

This is for C language:

Write a program that generates an array of integers of 1s and 0s. The program will use rand() function to generate 4 random positions for 1s and the rest of the array will be zeros. The program should include the following function where a is the array and n is the size of the array. void rand_position(int a[], int n);

The 4 random numbers should be unique. If the value at the position is already assigned to 1, your program should generate another random number. To use the rand() and time function, you need to include and .

Expected input/output #1:

Enter the size of the array:10

Output: 0 1 1 0 1 0 1 0 0 0

Another Expected input/output #2:

Enter the size of the array:8

Output: 1 0 1 0 0 1 1 0




Aucun commentaire:

Enregistrer un commentaire