/*Exercise 1: last name dot matrix*/
int main(){ printf(" * * * ********** * * \n"); printf(" * * * * * * * \n"); printf(" * * * * * * * \n"); printf(" * * * * * * * \n"); printf(" * * * * * * * \n"); printf("* ************ ********** * * * \n"); printf("* * * * * * * \n"); printf("* * * * * * * \n"); printf(" * * * * * * * \n"); printf(" * * * * * * * \n"); printf(" * * * * * ** \n"); printf(" * * * ********** * * \n");}
/* Exercise 2 (1): calculate area and perimeter*/
int main()
{
float a,b,area,pmeter;
printf("Please insert length a & b: ");
scanf("%f %f",&a,&b);
pmeter=(a+b)*2;
area=a*b;
printf("The perimeter is %f\n",pmeter);
printf("The area is %f\n",area);
return 0;
}
/*Exercise 2 (2): calculate resistance */
int main()
{
float a,b,r;
printf("Please insert R1 & R2: ");
scanf("%f %f", &a,&b);
r=1/(1/a+1/b);
printf("The resistance R is: %f\n",r);
return 0;
}
/*Exercise 2 (3): convert C to F */
int main()
{
float c,f;
printf("Please insert temperature in Celsius: ");
scanf("%f",&c);
f=c*9/5+32;
printf("%f Celsius is %f Fahrenheit \n",c,f);
return 0;
}
/* Exercise 2(4): calculate area for cylinder*/
int main()
{
float r,h,a;
printf("Please insert radius R and height H: ");
scanf("%f %f",&r,&h);
a=2*3.1415926*r*h+2*3.1415926*r*r;
printf("The surface area is: %f\n",a);
return 0;
}
小结:特别喜欢这门课,有时间花上十几分钟看看视频然后做做练习~ 感谢贺老师的无私奉献!
问题:小数点后面怎么规定取几位呢?刚发现用printf(“%.2f") 就好了