第二章
C语言概述
1、复习题
1、C语言基本模块——函数
2、语法错误——不遵循C语言的规则(可用编译器检测出来)
3、语义错误——意思上的错误(编译器检测不出来)
4、
#include<stdio.h>
int main(void)//改成打印一年有多少周
{
int s;
s=56;
printf("there are %d weeks in a year",s);
//getchar();
return 0;
}
5、
a输出
Baa Baa Black Sheep.Have you any wool?
b输出
Begone!
0 creature of land!
c输出
What?
No/nfish?
d输出
2+2=4;
6、关键字int、char
7、
int a=3020;
int b = 350;
printf("there were %d words and %d lines",a,b);
8.b=a=5;
#include<stdio.h>
int main(void)
{
int a, b;
a = 5;
b = 2;
b = a;
a = b;
printf("%d %d\n", b, a);
return 0;
}
9、x=150;y=15;
#include<stdio.h>
int main(void)
{
int x,y;
x=10;
y=5;
y=x+y;//15
x=x*y;//10*15=150
printf("%d %d",x,y);
return 0;
}
2、编程题
1、
printf("Gustav Mahler\n");
printf("Gustav\nMahler\n");
printf("Gustav ");
printf("Mahler\n");
2、
printf("Name:Tu Hei\n");
printf("Address:Najing instuate of techlogy\n");
3、
int age, days;
scanf_s("%d", &age);
days = 365 * age;
printf("i am %d years old,totally %d days\n", age, days);
4、
#include<stdio.h>
void jolly()
{
printf("For he is a jolly good fellow!\n");
}
void deny()
{
printf("Which nobody can deny!\n");
}
int main(void)
{
jolly();
jolly();
jolly();
deny();
return 0;
}
5、
#include<stdio.h>
void br()
{
printf("Brazil,Russia");
}
void ic()
{
printf("India,China");
}
int main(void)
{
br();
printf(",");
ic();
printf("\n");
ic();
printf(",\n");
br();
return 0;
}
6、#include<stdio.h>
int main(void)
{
int toes;
toes = 10;
printf("%d ,%d,%d", toes, 2 * toes,toes*toes);
return 0;
}
7、
#include<stdio.h>
void smile()
{
printf("smile!");
}
int main(void)
{
for (int i=0;i<3;i++)
{
for (int j = 0; j <3-i; j++)
{
smile();
}
printf("\n");
}
return 0;
}
8、
#include<stdio.h>
void one_three()
{
printf("one\n");
}
void two()
{
printf("two\n");
}
int main(void)
{
printf("starting now:\n");
one_three();;
two();
printf("three\n");
printf("done!\n");
return 0;
}