C语言(3)

时间:2021-05-22 06:07:19

C语言(3)----数据输入

输入时的关键字为scanf。如我们要从键盘上输入一个数,放在变量a里面,则可以写成scanf("%d",&a);

"&"符号为“取地址符”,简称“取址符 ”,作用是得到变量的地址。

#include <stdio.h>
#include <stdlib.h>
int main()
{
system("color 5F"); int a,b,c;
printf("请输入两个数值:\n");
scanf("%d %d",&a,&b);
c=a+b;
printf("%d+%d=%d\n",a,b,c); system("pause");
return ;
}

运行结果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdkAAACZCAIAAADsCteNAAAGSUlEQVR4nO3da27bOhCAUS8jy+nSDHRjdxddTvqjha8jksOhLHkc9wQHha3QerTAJ1aRncvHz1/Xy3Xk8/Nz6VvB+KUxj0tupR0Wv3Dz3eccC/D2Ln9aPGrKUov/LHk8x58rX7s3MX2QWa0WA4e43ObF9zHKhC94euzseHXN19xZ4X5MfhP7TgwAsU6L740WbgLUDpuG6bwWL43v7nny9LN0FACBS/d6cWbSt/lPfTfQQapOanEml8GsNt6WFgMn6bf4ZtSaBxs0mk3fD8h8PbK39/uwOa90X3W/xczOAORdPn7+2tQkk782YW2S4tRmBuQf7346OqLuS7rJnh4swNTkenHXKGTXr0V7WouTc+TbsHiFwRzZvBg4Sb/FcWva5Ustzsydd8yLgzUsjQl6bV4MnGTY4s24IFvX5hrFgS1uVxgEcbrD7d52zzRLxzuaF5ssA3l75sWbYdcwne1LpkumK4xbH6x2NGAzOHmGmB6XFgNJe+bFbaBPavFolx5vcRzfTIsz5yqApG2Lb3/GrWknqvfDRq2cNm60JJn1pe+OJrmZE4l5MXCsLy1eas2116Yd//HPb25pTHINo01rMfBM82sUS20azYunVcqHO96lpS3G+znKa/xV/i8KfEfD90AHT9vlt6hlJsgj8cQ83sOlAW00kxdVpBY4yeQ90AA8gRYD1NNigHpaDFBPiwHqbVs8vWUCgMNt3+sR3FRbvq8A78q8GKCeFgPU02KAeloMUE+LAeppMUA9LQaop8UA9Trv9di8s8NnpQOczedRAN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