#include <stdio.h> #include <stdlib.h> void decrescente(int vet[], int size) { int i, j, old; for (i = 0; i < size; i++) { for (j = 0; j < size - 1; j++) { if (vet[j] < vet[j+1]) { old = vet[j]; vet[j] = vet[j+1]; vet[j+1] = old; } } } } void crescente(int vet[], int size) { int i, j, old; for (i = 0; i < size; i++) { for (j = 0; j < size - 1; j++) { if (vet[j] > vet[j+1]) { old = vet[j]; vet[j] = vet[j+1]; vet[j+1] = old; } } } } int main() { int vet1[15] = { 5,6,90,40,20,30,16,32,64,2048,4096,9,10,11,23 }; int vet2[15] = { 5,6,90,40,20,30,16,32,64,2048,4096,9,10,11,23 }; int vet3[15] = { 5,6,90,40,20,30,16,32,64,2048,4096,9,10,11,23 }; int vet4[15] = { 5,6,90,40,20,30,16,32,64,2048,4096,9,10,11,23 }; int i, j, old; for (i = 0; i < 15; i++) { for (j = 0; j < 15 - 1; j++) { if (vet1[j] < vet1[j+1]) { old = vet1[j]; vet1[j] = vet1[j+1]; vet1[j+1] = old; } } } printf("Decrescente: "); for (i = 0; i < 15; i++) printf("%d ", vet1[i]); printf("\n"); for (i = 0; i < 15; i++) { for (j = 0; j < 15 - 1; j++) { if (vet2[j] > vet2[j+1]) { old = vet2[j]; vet2[j] = vet2[j+1]; vet2[j+1] = old; } } } printf("Crescente: "); for (i = 0; i < 15; i++) printf("%d ", vet2[i]); printf("\n"); printf("\nPor funcao:\n"); crescente(vet3, 15); printf("Crescente: "); for (i = 0; i < 15; i++) printf("%d ", vet3[i]); printf("\n"); decrescente(vet4, 15); printf("Decrescente: "); for (i = 0; i < 15; i++) printf("%d ", vet4[i]); printf("\n"); return 0; }
Learn More :
Bubble Sort
Example
- C Program String - Alphabet Count Example
- C Program Array Example: Average
- C Program Array Example: Reverse
- C Program Switch - Case Example
- C Program if - else if - else Example
- C Program Friend & Operator: Point2D Example
- C Program Friend & Operator: Vector Example
- C Program Recursion Example
- C Program Structure Example-2
- C Program Structure Example
- C Program Pointer Example
- C Program Function Example
- C Program String Example
- C Program Character Example
- C Program sizeof & memcpy Example
- C Program Array Example
- C Program Side Length Example
- C Program Pipes()
- C Program 0-1000 to Ordinary
- C Program Roboturtle
- C Program to Destroys a Mailbox
- C Program to Destroys a semaphore
- C Code for Testing the pH Meter V1.0
- APA 102c test program
- How To Retarget the C Library printf function to the UART.