Reginaldojs

exercicio 29,lista 4

Jul 29th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int main(){
  5.         int i=0;
  6.         char nome[3][30], aux[30];
  7.         for(i=0;i<3;i++){
  8.         printf("Por favor,entre com o nome %d:",i+1);
  9.         fgets(nome[i],30,stdin);}
  10.         int j;
  11.         for(j=1;j<3;j++){
  12.         strcpy(aux,nome[j]);
  13.         i = j-1;
  14.         while(i>=0&&strcmp(nome[i],aux)>0){
  15.         strcpy(nome[i+1],nome[i]);
  16.         i--;}
  17.         strcpy(nome[i+1],aux);
  18.         }
  19.         printf("\n\nNomes em ordem alfabetica: \n");
  20.         for(i=0;i<3;i++){
  21.         printf("%do nome-> %s",i+1,nome[i]);
  22.         }
  23.         system("pause");
  24.         return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment