1.
1 /* 2 編寫一程序要求任意輸入四位十六進制整數,以反序的方式輸出該十六進制數。 3 */ 4 #include <stdio.h> 5 6 int main() 7 { 8 char a, b, c, d; 9 scanf("%c%c%c%c", &a, &b, &c, &d); 10 printf("%c%c%c%c\n", d, c, b, a); 11 return 0; 12 }
2.
1 /* 2 編程從鍵盤輸入兩個整數分別給變量a和b,要求再不借助於其他變量的條件下將變量a和b的值實現交換。 3 */ 4 #include <stdio.h> 5 6 int main() 7 { 8 int a, b; 9 printf("輸入格式如下:\na = # , b = #\n"); 10 scanf("a = %d , b = %d", &a, &b); 11 a = a + b; 12 b = a - b; 13 a = a - b; 14 printf("a = %d , b = %d\n", a, b); 15 return 0; 16 }
3.
1 /* 2 編程從鍵盤輸入圓的半徑r,計算並輸出圓的周長和面積。 3 */ 4 #include <stdio.h> 5 #define PI 3.1415926 6 7 int main() 8 { 9 double r; 10 printf("請輸入半徑r:"); 11 scanf("%lf", &r); 12 printf("area = %.3f , prem = %.3f\n", PI * r *r, 2 * r * PI); 13 return 0; 14 }
4.
這個題有點意思哦,沒有說明該十六進制有多長,所以麻煩點在這里,可以利用循環。
輸入:-FA9824482
輸出:-FA9824482
1 /* 2 題目:編程從鍵盤輸入任意一十六進制負整數,以輸入的形式輸出。 3 例如:輸入-FA98,輸出-FA98 4 */ 5 #include <stdio.h> 6 7 int main() 8 { 9 long long int x; 10 scanf("%llx", &x); 11 printf("-%llX\n", -x); 12 return 0; 13 }
1 /* 2 編程從鍵盤輸入任意一十六進制負整數,以輸入的形式輸出。 3 例如:輸入-FA98,輸出-FA98 4 */ 5 #include <stdio.h> 6 7 int main() 8 { 9 char a; 10 do { 11 a = getchar(); 12 if(a != '\n') 13 printf("%c", a); 14 }while(a != '\n'); 15 printf("\n"); 16 return 0; 17 }
5.
1 /* 2 解二元一次方程 axx + bx + c = 0 3 輸入 a , b , c , 求解 x ; 4 */ 5 #include <stdio.h> 6 #include <math.h> 7 8 int main() 9 { 10 double a, b, c; 11 printf("請輸入三個變量a, b, c(a不能為0)\n"); 12 scanf("%lf %lf %lf", &a, &b, &c); 13 double x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a); 14 double x2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a); // sqrt(x),開根號函數 15 printf("x1 = %.5f , x2 = %.5f\n", x1, x2); 16 return 0; 17 }
6.
1 /* 2 假設從鍵盤輸入某日午夜零點到現在已經經歷的時間(秒),編一程序計算目前為止已過多少天,現在的時間是多少。 3 */ 4 #include <stdio.h> 5 6 int main() 7 { 8 long a; 9 printf("請輸入變量: a \n"); 10 scanf("%ld", &a); 11 printf("到目前為止已經經過了 %d 天\n", a / 86400); 12 printf("目前的時間是 %0.2d : %0.2d : %0.2d \n", a % 86400 / 3600, a % 86400 % 3600 / 60, a % 86400 % 3600 % 60); 13 return 0; 14 }
//
請輸入變量: a
86409
到目前為止已經經過了 1 天
目前的時間是 00 : 00 : 09
2021-07-12