vector aleatorio sin repetir
C
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <stdbool.h>
#define TAM 10
/*
Realizar un programa que rellene de forma aleatoria un vector
de 10 elementos con valores aleatorios entre 0 y 9 de forma
que no se repitan.
*/
void rellenar(int v[]){// 0 1 9
bool usados[TAM]; // false, false, ..., false
int valor;
for(int i = 0; i < TAM; i++){
usados[i] = false;
}
for(int i = 0; i < TAM; i++){
do{
valor = rand() % 10;
}while(usados[valor] == true);
usados[valor] = true;
v[i] = valor;
}
}
void imprimir(int v[]){
for(int i = 0; i <= TAM - 1; i++){
printf("vector[%d]: %d\n", i, v[i]);
}
}
int main (){
int v[TAM];
rellenar(v);
imprimir(v);
return 0;
}
Also in C:
- Title
- c string concatenation with int
- Category
- C
- Title
- error 403
- Category
- C
- Title
- diferencia entre * y & en c
- Category
- C
- Title
- use of matplotlib inline
- Category
- C
- Title
- c concatenate strings
- Category
- C
- Title
- python web crawler
- Category
- C
- Title
- pop and push shows black screen which needs to be pressed back flutter
- Category
- C
- Title
- pass the pointer in C
- Category
- C
- Title
- lelcetric fied
- Category
- C
- Title
- maximo comun divisor
- Category
- C
- Title
- windeployqt example
- Category
- C
- Title
- oop244
- Category
- C
- Title
- print variable c
- Category
- C
- Title
- where is my vimrc
- Category
- C
- Title
- how to put quotes inside string c
- Category
- C
- Title
- what are the causes of memory leaks in c
- Category
- C
- Title
- latex font sizes
- Category
- C
- Title
- inurl:fiu.edu math faculty
- Category
- C
- Title
- kadane's algorithm
- Category
- C
- Title
- what is a long long int in c
- Category
- C
- Title
- command line coursera
- Category
- C
- Title
- tar cmd
- Category
- C
- Title
- function in c
- Category
- C
- Title
- add border to image android
- Category
- C
- Title
- entete c/c++
- Category
- C
- Title
- error: ‘cout’ was not declared in this scope
- Category
- C
- Title
- c bitwise operators
- Category
- C
- Title
- strcat in c
- Category
- C
- Title
- resto de division recursiva
- Category
- C
- Title
- how to globally initlailize a struct
- Category
- C
- Title
- random en c
- Category
- C
- Title
- c isdigit function
- Category
- C
- Title
- strrev in c
- Category
- C
- Title
- how to login to another user in powershell
- Category
- C
- Title
- c check if array is empty
- Category
- C
- Title
- How to pull images from Docker Registry
- Category
- C
- Title
- azure storage emulator config
- Category
- C
- Title
- delete docker image repository none
- Category
- C
- Title
- what is stdin in c
- Category
- C
- Title
- a enum data type in c
- Category
- C
- Title
- Declare macro
- Category
- C
- Title
- c array
- Category
- C
- Title
- declaring a volatile in c
- Category
- C
- Title
- qtableview get selected row
- Category
- C
- Title
- what is the meaningof noremap
- Category
- C
- Title
- pointer parameter where to put the asterix in C?
- Category
- C
- Title
- bella ciao lyrics
- Category
- C
- Title
- remove element queue
- Category
- C
- Title
- piramide
- Category
- C
- Title
- c printf uint32_t
- Category
- C
- Title
- change a attribute in dataframe
- Category
- C
- Title
- css selector for sibling element
- Category
- C
- Title
- version of libgcc
- Category
- C
- Title
- c allocate array
- Category
- C
- Title
- docker pull command
- Category
- C
- Title
- write a binary file c
- Category
- C
- Title
- How to setup a line length marker in vim
- Category
- C
- Title
- passing 2d array as parameter to function in c
- Category
- C
- Title
- csrf_exempt
- Category
- C
- Title
- stack
- Category
- C
- Title
- c print array
- Category
- C
- Title
- docker images command
- Category
- C
- Title
- typedef vs #define
- Category
- C
- Title
- select all file from date powershell
- Category
- C
- Title
- scanf read line
- Category
- C
- Title
- c check if char is number
- Category
- C
- Title
- concatenate two strings in c
- Category
- C
- Title
- c fill 2d array
- Category
- C
- Title
- how to use a pointer as a parameter in c
- Category
- C
- Title
- how to put a struct in another struct C
- Category
- C
- Title
- C/c drop mime
- Category
- C
- Title
- measure time in c
- Category
- C
- Title
- for loop in c
- Category
- C
- Title
- disable gnu++11 option
- Category
- C
- Title
- hentai clochette
- Category
- C
- Title
- c pause for 1 second
- Category
- C
- Title
- c radians
- Category
- C
- Title
- c print hello world
- Category
- C
- Title
- es fibo
- Category
- C
- Title
- PS1 modified lags
- Category
- C
- Title
- sleep in c programming
- Category
- C
- Title
- append to list in c
- Category
- C
- Title
- how to get random numbers in c
- Category
- C
- Title
- es vocal
- Category
- C
- Title
- what is x:Name Xamarin forms
- Category
- C
- Title
- c defined value sum
- Category
- C
- Title
- variadic function in c
- Category
- C
- Title
- bash: apt-add-repository: command not found
- Category
- C
- Title
- atoi
- Category
- C
- Title
- how to use ? in c
- Category
- C
- Title
- first person view unity
- Category
- C
- Title
- get regedit value cmd
- Category
- C
- Title
- ModuleNotFoundError: No module named 'easydict'
- Category
- C
- Title
- how to open a website in c
- Category
- C
- Title
- battlefield4u.com
- Category
- C
- Title
- matplotlib plot circle marker
- Category
- C
- Title
- switch case c
- Category
- C
- Title
- remove an element from a set
- Category
- C
- Title
- uint32_t extract first bits
- Category
- C
- Title
- vbl share price
- Category
- C