31 Aralık 2012 Pazartesi


2.3 輸入一個24制時間轉換成12制時間,並加上AM/PM。
輸入的時間必須符合24進制,否則為error!! 

例如:

Input
23:15

Output
11:15 PM

Input
16:61

Output
error!!

Input
03:18  

Output
03:18 AM

  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3.   
  4. int main(int argc, char *argv[])  
  5. {  
  6.  int a,c;  
  7.   
  8.  scanf("%d:%d",&a,&c);  
  9.  if((a>=0)&&(a<25)&&(c<61)&&(c>=0))  
  10.   {  
  11.    if(a>12)  
  12.     printf("%d:%d PM\n",a-12,c);  
  13.    else  
  14.     printf("%d:%d AM\n",a,c);  
  15.   }  
  16.    else printf("error!!\n");  
  17.           
  18.   system("PAUSE");    
  19.   return 0;  
  20. }  

Hiç yorum yok:

Yorum Gönder

Binary Conversion

Problem Description Convert two binary numbers into two decimal numbers and compute their sum. Your program has to convert two binary number...