c语言中指针作为参数的函数同时计算两个数的和与差。
1、
#include <stdio.h> void sum_dif(int n1, int n2, int *sum, int *dif) { *sum = n1 + n2; *dif = (n1 > n2) ? (n1 - n2) : (n2 - n1); } int main(void) { int na, nb, wa = 0, sa = 0; puts("please input two integers."); printf("na = "); scanf("%d", &na); printf("nb = "); scanf("%d", &nb); sum_dif(na, nb, &wa, &sa); printf(" wa: %d sa: %d ", wa, sa); return 0; }