第5节 数据输出---我说咋的就咋地
- 格式:doc
- 大小:20.50 KB
- 文档页数:3
第5节数据输出---我说咋的就咋地新的代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c;
a=1;
b=2;
c=a+b;
printf(“%d+%d=%d”,a,b,c);
system(“pause”);
return 0;
}
原来的代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c;
a=1;
b=2;
c=a+b;
printf(“%d”,c);
system(“pause”);
return 0;
}
注意:通常双引号内部的“%d”的个数,和后面变量的个数是相等的,它们是一一对应的。
如果没有一一对应,从c语言的语法角度来讲是没有错误的,但这不合常理,最好避免这样的情况出现。
改错:下面这段代码是计算机分别计算10-5和10+5的值,并分两行显示,第一行显示差,第二行显示和。
其中有3个错误。
#include <stdio.h>
#include <stdlib.h>
int mian()
{
int a,b,c;
a=10;
b=5;
c=a-b;
printf(“%d/n”,c);
c=a+b;
printf(“%d”,c);
system(“pause”);
return 0;
}
作业:指定两个数,输出这两个数的和、差、积与商。