㈠ 用c语言,输入两个整数x,y,基于子函数的形式分别计算这两个数的和、差、积、商
具体输入如下:
#include "stdio.h"
main()
{ int a,b;
printf("请输入两个整数(a,b):");
scanf("%d,%d",&a,&b);
printf("和:%d ",a+b);
printf("差:%d ",a-b);
printf("积:%d ",a*b);
printf("商:%f ",(float)a/b);}
㈡ C语言 编写函数同时求两个整数的和与差
#include "stdio.h"
int Add_Sub(int *p,int *q,int *s){
*s=*p-*q;
return *p+*q;
}
int main(int argc,char *argv[]){
int x,y,z;
printf("Enter x & y(int)...
");
scanf("%d%d",&x,&y);
printf("
x+y = %d
",Add_Sub(&x,&y,&z));
printf("x-y = %d
",z);
return 0;
}
(2)c语言计算两数和与差的函数扩展阅读:
C语言包含的各种控制语句仅有9种,关键字也只有32 个,程序的编写要求不严格且以小写字母为主,对许多不必要的部分进行了精简。实际上,语句构成与硬件有关联的较少,且C语言本身不提供与硬件相关的输入输出、文件管理等功能,如需此类功能,需要通过配合编译系统所支持的各类库进行编程,故c语言拥有非常简洁的编译系统。
㈢ c语言程序设计. 由键盘输入两个整数,分别计算这两个数的和、差、积、商,并输出结果
#include "stdio.h"
main()
{ int a,b;
printf("请输入两个整数(a,b):");
scanf("%d,%d",&a,&b);
printf("和:%d
",a+b);
printf("差:%d
",a-b);
printf("积:%d
",a*b);
printf("商:%f ",(float)a/b);}
㈣ C语言:用函数和指针方法同时求给定两个整数x与y的和及差,咋写
代码文本:
#include "stdio.h"
int Add_Sub(int *p,int *q,int *s){
*s=*p-*q;
return *p+*q;
}
int main(int argc,char *argv[]){
int x,y,z;
printf("Enter x & y(int)... ");
scanf("%d%d",&x,&y);
printf(" x+y = %d ",Add_Sub(&x,&y,&z));
printf("x-y = %d ",z);
return 0;
}
㈤ 用C语言编写(计算两个整数的和、 差、积、商与余数
代码一:
#include<stdio.h>
int main(void)
{
int num1, num2;
scanf("%d%d",&num1,&num2);
printf("%d + %d = %d ",num1,num2,num1+num2);
printf("%d - %d = %d ", num1, num2, num1-num2);
printf("%d * %d = %d ", num1, num2, num1*num2);
if (num2) printf("%d / %d = %g ", num1, num2, (double)num1/num2);
else printf("ERROR ,DIVBYZERO ");
printf("%d %% %d = %d ", num1, num2, num1%num2);
return 0;
}
代码二:
#include <stdio.h>
void main()
{
int x, y;
printf("please enter a,b,c:");
scanf("%d,%d",&x,&y);
printf(" x+y=%d ",x+y);
printf("x-y=%d ",x-y);
printf("x*y=%d ",x*y);
printf("x/y=%d ",x/y);
printf("x%%y=%d ",x%y);
}
下图为C语言算术运算符:
(5)c语言计算两数和与差的函数扩展阅读:
算术运算符实例:
#include <stdio.h>
main()
{
int a = 21;
int b = 10;
int c ;
c = a + b;
printf("Line 1 - c 的值是 %d ", c );
c = a - b;
printf("Line 2 - c 的值是 %d ", c );
c = a * b;
printf("Line 3 - c 的值是 %d ", c );
c = a / b;
printf("Line 4 - c 的值是 %d ", c );
c = a % b;
printf("Line 5 - c 的值是 %d ", c );
c = a++;
printf("Line 6 - c 的值是 %d ", c );
c = a--;
printf("Line 7 - c 的值是 %d ", c );
}