从用户读取两个字符并进行比较

#include stdio.hint main(){char a,b;printf(Which character is greater?\\n);printf(Type a single character:);

编程学习网为您整理以下代码实例,主要实现:从用户读取两个字符并进行比较,希望可以帮到各位朋友。

#include <stdio.h>
int main()
{
   char a,b;
   printf("Which character is greater?\n");
   printf("Type a single character:");
   a=getchar();
   printf("Type another character:");
   b=getchar();
   if(a > b)
   {
      printf("'%c' is greater than '%c'!\n",a,b);
   }
   else if (b > a)
   {
      printf("'%c' is greater than '%c'!\n",b,a);
   }
   else{
      printf("Next time, don't type the same character twice.");
   }
   return(0);
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐