鱼C论坛

 找回密码
 立即注册
查看: 1501|回复: 3

[已解决]大神们,如何将这个函数拆分为两个函数,并且依旧能够循环

[复制链接]
发表于 2021-11-10 09:19:27 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 wwWsir 于 2021-11-10 09:38 编辑
  1. #include <stdio.h>

  2. int main(void)
  3. {
  4.         float R1 , R2 , Av                                                  ;
  5.         char ch                                                             ;
  6.         for(;;) {
  7.                 printf("\n")                                                ;
  8.                 printf("please enter two number : ")                        ;
  9.                 scanf("%f%f" , & R1 , &R2)                                  ;
  10.                 if(R1 < 0 || R2 <= 0) {
  11.                         printf("*** Error : please enter right number !\n") ;
  12.                 } else {
  13.                         Av = (R1 + R2) / R2                                 ;
  14.                         printf("Av =%f\n\n" , Av)                           ;
  15.                         printf("Go on (Y/N) : ?")                           ;
  16.                         fflush(stdin)                                       ;
  17.                         if((ch = getchar()) != 'Y' && ch != 'y') break      ;
  18.                 }
  19.         }
  20. }
复制代码
最佳答案
2021-11-10 09:43:28

  1. #include <stdio.h>

  2. float calculation(float a,float b)
  3. {
  4.     float  Av;
  5.     Av = (a + b) / b;
  6.     return Av;
  7. }
  8. int main(void)
  9. {
  10.         float R1 , R2,num ;
  11.         char ch ;
  12.         for(;;) {
  13.                 printf("\n") ;
  14.                 printf("please enter two number : ");
  15.                 scanf("%f %f" , & R1 , &R2);
  16.                 if(R1 < 0 || R2 <= 0) {
  17.                         printf("*** Error : please enter right number !\n") ;
  18.                 } else {
  19.                         num = calculation(R1,R2);
  20.                         printf("Av =%f\n\n" , num);
  21.                         printf("Go on (Y/N) : ?") ;
  22.                         fflush(stdin) ;
  23.                         if((ch = getchar()) != 'Y' && ch != 'y') break;
  24.                 }
  25.         }
  26. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-10 09:29:47 | 显示全部楼层
这怎么拆还不是看你心情,想拆啥拿出来啥就行了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-11-10 09:31:09 | 显示全部楼层
村里小黑 发表于 2021-11-10 09:29
这怎么拆还不是看你心情,想拆啥拿出来啥就行了

啊,那这该怎么拆啊,我刚刚自己拆了试了试都不能循环啦,小白一枚。。。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-10 09:43:28 | 显示全部楼层    本楼为最佳答案   

  1. #include <stdio.h>

  2. float calculation(float a,float b)
  3. {
  4.     float  Av;
  5.     Av = (a + b) / b;
  6.     return Av;
  7. }
  8. int main(void)
  9. {
  10.         float R1 , R2,num ;
  11.         char ch ;
  12.         for(;;) {
  13.                 printf("\n") ;
  14.                 printf("please enter two number : ");
  15.                 scanf("%f %f" , & R1 , &R2);
  16.                 if(R1 < 0 || R2 <= 0) {
  17.                         printf("*** Error : please enter right number !\n") ;
  18.                 } else {
  19.                         num = calculation(R1,R2);
  20.                         printf("Av =%f\n\n" , num);
  21.                         printf("Go on (Y/N) : ?") ;
  22.                         fflush(stdin) ;
  23.                         if((ch = getchar()) != 'Y' && ch != 'y') break;
  24.                 }
  25.         }
  26. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-25 18:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表