明解C語言 入門篇 第二章答案


 

練習2-1

 1 #include <stdio.h>
 2 
 3 int main() {
 4     int x;
 5     int y;
 6     int percent;
 7     
 8     puts("請輸入兩個整數");
 9     printf("整數x:");
10     scanf("%d", &x);
11     printf("整數y:");
12     scanf("%d", &y);
13     percent = (x *100 )/ y;
14     printf("x的值是y的%d%%", percent);
15 
16     return 0;
17 }

練習2-2

 1 #include <stdio.h>
 2 
 3 int main() {
 4     int x;
 5     int y;
 6     
 7     puts("請輸入兩個整數");
 8     printf("整數x:");
 9     scanf("%d", &x);
10     printf("整數y:");
11     scanf("%d", &y);
12     printf("他們的和是%d,積是%d", x+y,x*y);
13 
14     return 0;
15 }

練習2-3

1 #include <stdio.h>
2 
3 int main() {
4     double x;
5     printf("請輸入一個實數:");
6     scanf("%lf", &x);
7     printf("你輸入的值是:%f", x);
8     return 0;
9 }

練習2-4

練習2-5

 1 #include <stdio.h>
 2 
 3 int main() {
 4     int x;
 5     int y;
 6     puts("請輸入兩個整數。");
 7     printf("整數a:");
 8     scanf("%d", &x);
 9     printf("整數b:");
10     scanf("%d", &y);
11     printf("a是b的%f%%", (double)x / y * 100);
12     return 0;
13 }

 

練習2-6

 1 #include <stdio.h>
 2 
 3 int main() {
 4     int x;
 5     printf("請輸入你的身高:");
 6     scanf("%d", &x);
 7     printf("您的標准體重是:%.1f公斤", (x - 100) * 0.9);
 8     
 9     return 0;
10 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM