第四讲: C语言程序设计初体验

时间:2023-01-21 08:52:17
/*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");}

第四讲: C语言程序设计初体验


/* 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;
}
第四讲: C语言程序设计初体验

/*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;
}

第四讲: C语言程序设计初体验

/*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*/

第四讲: C语言程序设计初体验

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;

}

第四讲: C语言程序设计初体验

小结:特别喜欢这门课,有时间花上十几分钟看看视频然后做做练习~ 感谢贺老师的无私奉献!

问题:小数点后面怎么规定取几位呢?刚发现用printf(“%.2f") 就好了