Advertisement
gtw7375

Função e Vetor em C

Oct 30th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. void armazenar(int vet[], int qtd);
  5. void ordenar(int vet[], int qtd, int tipo);
  6. void escrever(int vet[], int qtd);
  7.  
  8. main(){
  9.  
  10. int numero[10], q=10, x;
  11.  
  12. armazenar(numero,q);
  13. ordenar(numero,10,0);
  14. escrever(numero,10);
  15.  
  16. getch();
  17. }
  18.  
  19. void armazenar(int vet[], int qtd){
  20. int x;
  21.  
  22. for(x=0; x<10; x++){
  23. scanf("%d", vet[x]);
  24. }
  25. }
  26.  
  27. void ordenar(int vet[], int qtd, int tipo){
  28. int x,y,aux;
  29.  
  30. if(tipo==0){
  31.  
  32. for(x=0; x<qtd; x++){
  33. for(y=0; y<qtd; y++){
  34.  
  35. if(vet[x]<vet[y]){
  36. aux=vet[x];
  37. vet[x]=vet[y];
  38. vet[y]=aux;
  39. }
  40. }
  41. }
  42. } else {
  43.  
  44. for(x=0; x<qtd; x++){
  45. for(y=0; y<qtd; y++){
  46.  
  47. if(vet[x]<vet[y]){
  48. aux=vet[x];
  49. vet[x]=vet[y];
  50. vet[y]=aux;
  51. }
  52.  
  53. } } } }
  54. void escrever(int vet[], int qtd){
  55. int x;
  56.  
  57. for(x=0; x<qtd; x++){
  58. printf("%d\n", vet[x]);
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement