本帖最后由 gululu23 于 2014-12-14 10:41 编辑
直接上 代码- //
- // main.m
- // dheiu
- //
- // Created by 咕噜噜的mac on 14-12-14.
- // Copyright (c) 2014年 咕噜噜的mac. All rights reserved.
- //
- #include <stdio.h>
- void sumAndMinusAndMultiplyAndQuotientAndResidue(int a, int b,int *sum, int *minus,int *multiply, int *quotient, int *residue);
- int main()
- {
-
- //提示输入两个数
- printf("请输入两个整数,并以空格符号隔开\n");
-
- //定义两个变量
- int a,b;
-
- //接受两个变量
- scanf("%d %d",&a , &b);
-
- //定义变量和、差、积、商、余数
- int sum , minus , multiply , quotient , residue;
-
- //调用函数,并传入和、差、积、商、余数的变量地址
-
- sumAndMinusAndMultiplyAndQuotientAndResidue(a, b, &sum, &minus, &multiply, "ient, &residue);
-
- //输入两数的和、差、积、商、余数
- // printf("%d + %d = %d \n %d - %d = %d \n %d * %d = %d \n %d / %d = %d \n %d %% %d = %d\n ", a , b ,sum ,a , b , minus , a , b ,multiply , a , b ,quotient , residue );
- printf("%d + %d = %d\n",a, b, sum);
- printf("%d - %d = %d\n",a ,b , minus);
- printf("%d * %d = %d\n",a , b, multiply);
- printf("%d / %d = %d\n",a , b, quotient);
- printf("%d %% %d = %d\n",a, b, residue);
-
- return 0;
- }
- //定义函数,计算两数和、差、积、商、余数
- void sumAndMinusAndMultiplyAndQuotientAndResidue(int a, int b,int *sum, int *minus,int *multiply, int *quotient, int *residue)
- {
- //和
- *sum = a + b;
-
- //差
- *minus = a - b;
-
- //积
- *multiply = a * b;
-
- //商
- *quotient = a / b;
-
- //余数
- *residue = a % b;
-
- }
复制代码
问题1:如果用上面的scanf函数一次全部输出的时候,会有警告?
问题2:用xcode运行的时候,只能输入只能显示一个数数字,但运算结果是正确的?请大神亲测 下
|
|