第一次作业
1. #include <stdio.h>
int main()
{
printf("*********\n");
printf(" *******\n");
printf(" *****\n");
printf(" ***\n");
printf(" *\n");
return 0;
}
int main()
{
printf("*********\n");
printf(" *******\n");
printf(" *****\n");
printf(" ***\n");
printf(" *\n");
return 0;
}
![](https://images2015.cnblogs.com/blog/1032137/201610/1032137-20161003121515832-1103817710.jpg)
实验总结:打*之后记得打换行符,不要忘记打封号。
2. #include <stdio.h>
int main()
{
int a,b,c,sum;
printf("请输入三个整数,并求和");
scanf("%d%d%d",&a,&b,&c);
sum=a+b+c;
printf("和为%d\n",sum);
return 0;
}
int main()
{
int a,b,c,sum;
printf("请输入三个整数,并求和");
scanf("%d%d%d",&a,&b,&c);
sum=a+b+c;
printf("和为%d\n",sum);
return 0;
}
![](https://images2015.cnblogs.com/blog/1032137/201610/1032137-20161003121611692-946920135.png)
实验总结:输入的%d之间是什么样的,最后在执行时就是什么样的,切记不要弄错,要不程序就运行不了。
3. #include <stdio.h>
int main()
{
int year1,year2,month1,month2,day1,day2,old;
printf("请输入今天的日期:\n");
scanf("%d,%d,%d",&year1,&month1,&day1);
printf("请输入你的生日:\n");
scanf("%d-%d-%d",&year2,&month2,&day2);
old=year1-year2;
printf("你今年%d岁了,你的生日是%d-%d-%d",old,year2,month2,day2);
return 0;
}
int main()
{
int year1,year2,month1,month2,day1,day2,old;
printf("请输入今天的日期:\n");
scanf("%d,%d,%d",&year1,&month1,&day1);
printf("请输入你的生日:\n");
scanf("%d-%d-%d",&year2,&month2,&day2);
old=year1-year2;
printf("你今年%d岁了,你的生日是%d-%d-%d",old,year2,month2,day2);
return 0;
}
![](https://images2015.cnblogs.com/blog/1032137/201610/1032137-20161003121650692-990710872.png)
实验总结:注意其中的标点符号为英文半角,不要在输完中文之后,忘记切换输入法。
4.#include <stdio.h>
int main()
{
int a,b,c,temp;
printf("请输入三个数:");
scanf("%d%d%d",&a,&b,&c);
temp=a;
a=b;
b=c;
c=temp;
printf("交换后为%d,%d,%d",a,b,c);
return 0;
}
实验总结:搞清楚交换的步骤,不要弄错了。
5.#include <stdio.h>
int main()
{
int min1,hour,min2;
printf("输入X分钟,将其换算成小时和分钟:");
scanf("%d",&min1);
hour=min1/60;
min2=min1%60;
printf("%d分钟=%d小时%d分钟",min1,hour,min2);
return 0;
}
实验总结 :括号里记得加引号
6.#include <stdio.h>
int main()
{
int a,b,c,d,e,f;
printf("输入四位数:");
scanf("%d",&a);
b=a/1000;
c=a/100%10;
d=a/10%10;
e=a%10;
f=e*1000+d*100+c*10+b;
printf("倒序为%04d\n",f);
return 0;
}
实验总结:搞清楚/、%的关系,不要弄错。
7.#include <stdio.h>
int main()
#define PI 3.1415926
{
int r;
float c,v;
printf("输入半径:");
scanf("%d",&r);
c=2*PI*r;
v=4.0/3*PI*r*r*r;
printf("周长为%.2f,体积为%.2f\n",c,v);
return 0;
}
int main()
#define PI 3.1415926
{
int r;
float c,v;
printf("输入半径:");
scanf("%d",&r);
c=2*PI*r;
v=4.0/3*PI*r*r*r;
printf("周长为%.2f,体积为%.2f\n",c,v);
return 0;
}
![](https://images2015.cnblogs.com/blog/1032137/201610/1032137-20161003121838832-421077383.png)
实验总结:最后要求保留两位小数,要记得类型变换。