㈠ 用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 );
}