标题: 求帮助,提供一下c语言思路 [打印本页]

作者: Qing1218    时间: 2017-2-17 15:07
标题: 求帮助,提供一下c语言思路
有四路数据,怎样用C语言实现四路数据哪路被选通
作者: angmall    时间: 2017-2-17 16:41
c语言使用switch编写
switch  是一个开关语句,和case配套使用, 和if else 判断语句差不多, switch  语句是用于多分支语句进行条件判断。下例为用switch语句编写的四则运算:
  1. #include <stdio.h>
  2. void main()
  3. {
  4.    double N1,N2;
  5.    char Operation;
  6.    printf("输入运算的两个数");
  7.    scanf("%lf%lf",&N1,N2);
  8.    printf("请输入运算符(+,-,*,/):");
  9.    switch(Operation)
  10.    {
  11.         case '+':printf("%lf%c%lf=%lf",N1,N2,Operation,N1+N2);
  12.           break;   
  13.         case '-':printf("%lf%c%lf=%lf",N1,N2,Operation,N1-N2);
  14.           break;   
  15.         case '*':printf("%lf%c%lf=%lf",N1,N2,Operation,N1*N2);
  16.           break;   
  17.         case '/':printf("%lf%c%lf=%lf",N1,N2,Operation,N1/N2);
  18.           break;   
  19.   }  
  20. }
复制代码


作者: webb_2002    时间: 2017-2-17 16:54
楼上的说的很明白。收藏!
作者: 5102067070    时间: 2017-2-17 19:19
用SWITH CASE语句.
作者: Chandler1983    时间: 2017-2-17 21:56
你应该用电路实现吧,CD4052
作者: Qing1218    时间: 2017-2-18 14:37
Chandler1983 发表于 2017-2-17 21:56
你应该用电路实现吧,CD4052

恩恩,用的4051,,单片机用的atmega128,
作者: Qing1218    时间: 2017-2-18 14:38
5102067070 发表于 2017-2-17 19:19
用SWITH CASE语句.

恩恩,谢谢

作者: Qing1218    时间: 2017-2-18 14:38
angmall 发表于 2017-2-17 16:41
c语言使用switch编写
switch  是一个开关语句,和case配套使用, 和if else 判断语句差不多, switch  语 ...

谢谢,收藏




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1