diogoAlves

IFF/Introdução à Programação/Lista/98

Mar 8th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. //IFF - Introdução à Programação
  2. //Lista de Exercícios - Exercício 98
  3. #include<stdio.h>
  4. #include<locale.h>
  5. #include<string.h>
  6.  
  7. char time[2];
  8. int Converter(int h){
  9.     if(h>12){
  10.         h-=12;
  11.         strcpy(time,"pm"); 
  12.     }else{
  13.         strcpy(time,"am");
  14.     }
  15.     return h;
  16. }
  17. int main(){
  18.     setlocale(LC_ALL,"Portuguese");
  19.     int h, m;
  20.     char resposta[3];
  21.     do{
  22.         printf("\nEntre, respectivamente, com a hora e minutos: ");
  23.         scanf("%d%d",&h,&m);
  24.         if(h<24){
  25.             if(m>59){
  26.                 h++;
  27.                 m-=60;
  28.             }
  29.             h=Converter(h);
  30.             printf("São %d:%d %s.\n\n",h,m,time);
  31.         }else printf("Entre com um valor de hora válido.");
  32.         setbuf(stdin,NULL);
  33.         printf("Deseja nova consulta?\n",time);
  34.         gets(resposta);
  35.     }while (stricmp(resposta,"sim")==0);
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment