vector aleatorio sin repetir
#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:
- c fork wait for child
- powershell some fonts like #include are dissapearing
- switch case c
- Print the number 0 using write()
- Declare macro
- c isdigit function
- c waitpid
- write a program to ask the user 8 integer numbers. your program will then move all negative elements of your array to the end of the array without changing the order of positive elements and negative elements
- how to find the nth row of pascal's triangle in c
- what is x:Name Xamarin forms
- cannot update windows 10
- c how to define a variable
- !isdigit c
- run a command in cmd with c
- dani
- jsdocs returns
- fibonacci sequence single recursive call
- cannot reach esp8266 via udp while he is running with a static ip
- how to read space separated words in c
- arduino server read
- main function in c
- c \a
- ruby find object in array by attribute
- c calloc