/*(1)编程序,输入长方形的两边长a和b,输出长方形的周长和面积
提示:边长可以是整数也可以是小数;实现乘法的运算符是* */
#include <stdio.h>
int main()
{
float a, b, perimeter, area;
printf("Please enter a and b: ");
scanf("%f %f", &a, &b);
perimeter =(a + b) * 2;
area = a * b;
printf("perimeter = %.2f, area = %.2f\n", perimeter, area);
return 0;
}
/*
Please enter a and b: 20 30
perimeter = 100.00, area = 600.00
Process returned 0 (0x0) execution time : 7.435 s
Press any key to continue.
*/
/*(2)编程序,输入两个电阻R1和R2的阻值,求它们并联后的阻值R
提示:计算公式为r=1/(1/r1+1/r2));电阻值为浮点数 */
#include <stdio.h>
int main()
{
float R, R1, R2;
printf("Please enter R1 and R2: ");
scanf("%f %f", &R1, &R2);
R = 1.0 / (1 / R1 + 1 / R2);
printf("R = %.2f\n", R);
return 0;
}
/*
Please enter R1 and R2: 5 7
R = 2.92
Process returned 0 (0x0) execution time : 2.312 s
Press any key to continue.
*/
/*(3)输入摄氏温度值(C),转换为华氏温度值(F)并输出
提示:F=C×9/5+32,温度值取浮点数类型。*/
#include <stdio.h>
int main()
{
float Celsius, Fahrenheit;
printf("Please enter celsius: ");
scanf("%f", &Celsius);
Fahrenheit = Celsius * 9 / 5 + 32;
printf("%.2f celsius = %.2f Fahrenheit.\n", Celsius, Fahrenheit);
return 0;
}
/*
Please enter celsius: 100
100.00 celsius = 212.00 Fahrenheit.
Process returned 0 (0x0) execution time : 2.070 s
Press any key to continue.
*/
/*(4)编程序,输入圆柱体的半径r和高h,输出圆柱体的表面积s。
提示:π值直接写3.1415926
样例输入:3.5 9
样例输出:Area = 274.889 */
#include <stdio.h>
#define PI 3.14
int main()
{
float R, H, Area;
printf("Please R and H: ");
scanf("%f %f", &R, &H);
Area = 2 * PI * R * R + 2 * PI * R * H; //S表=2πr*r+2πrh
printf("Area = %.2f\n", Area);
return 0;
}
/*
Please R and H: 3.5 9
Area = 274.75
Process returned 0 (0x0) execution time : 3.563 s
Press any key to continue.
*/
——————————————————————————————————————————————————————————————————
<pre name="code" class="cpp">#include <stdio.h>
int main() //姓名读音首字母
{
printf("* * * * * * * *\n");
printf("* * * * *\n");
printf("* * * * *\n");
printf("* * * * * * * *\n");
printf("* * * * *\n");
printf("* * * * * *\n");
printf("* * * * * * * *\n");
return 0;
}
/*
* * * * * * * *
* * * * *
* * * * *
* * * * * * * *
* * * * *
* * * * * *
* * * * * * * *
Process returned 0 (0x0) execution time : 0.335 s
Press any key to continue.
*/