Compare commits

..
252 Commits
Author SHA1 Message Date
smallkun c9dd5c8c83 Auto commit 2026-03-16 22:36:32 +08:00
smallkun e7aae27f87 Auto commit 2026-03-12 10:56:48 +08:00
smallkun c097a27e34 Auto commit 2025-05-08 17:47:28 +08:00
smallkun e6afc51134 Auto commit 2025-04-21 19:41:17 +08:00
smallkun db0782e5fc Auto commit 2025-04-06 18:37:03 +08:00
smallkun d7e3a5c9d9 Auto commit 2025-04-06 01:18:11 +08:00
smallkun 3d52dadba1 Auto commit 2025-04-06 01:17:50 +08:00
smallkun 3fbfc647b8 Auto commit 2025-04-06 01:15:20 +08:00
smallkun 2c43525475 Auto commit 2025-04-06 01:15:03 +08:00
smallkun 3f9704f1a4 Auto commit 2025-04-06 01:13:51 +08:00
smallkun f725ee8c97 Auto commit 2025-04-05 19:25:52 +08:00
smallkun 2c3e944e03 Auto commit 2025-04-05 19:14:42 +08:00
smallkun 1918e1e1e7 Auto commit 2025-04-05 18:10:11 +08:00
smallkun c96d28c005 Auto commit 2025-04-05 18:09:56 +08:00
smallkun 0ab49e8346 Auto commit 2025-04-03 11:55:09 +08:00
smallkun 1725b35ac9 Auto commit 2025-04-03 11:03:28 +08:00
smallkun 1a1a6c0409 Auto commit 2025-04-03 10:46:38 +08:00
smallkun 39672f95cb Auto commit 2025-04-03 10:23:32 +08:00
smallkun 712b37490c Auto commit 2025-04-03 10:19:55 +08:00
smallkun 449f17509e Auto commit 2025-04-02 19:51:05 +08:00
smallkun cd169b4904 Auto commit 2025-04-02 19:35:26 +08:00
smallkun d31fe4ec44 Auto commit 2025-04-02 19:34:45 +08:00
smallkun dc74003746 Auto commit 2025-04-02 00:23:03 +08:00
smallkun e8fd54dc02 Auto commit 2025-04-01 23:54:12 +08:00
smallkun c573ab7540 Auto commit 2025-04-01 20:11:46 +08:00
smallkun 53b34d917f Auto commit 2025-04-01 18:56:19 +08:00
smallkun 4079ff9b07 Auto commit 2025-04-01 17:02:00 +08:00
smallkun fc813427c5 Auto commit 2025-04-01 16:54:59 +08:00
smallkun 255a4afc97 Auto commit 2025-04-01 16:49:40 +08:00
smallkun dc8392a55c Auto commit 2025-04-01 16:39:57 +08:00
smallkun b5cc50f90d Auto commit 2025-04-01 16:38:21 +08:00
smallkun da63a1d634 Auto commit 2025-04-01 16:36:23 +08:00
smallkun fc66b14900 Auto commit 2025-04-01 16:27:10 +08:00
smallkun 49499ddb60 Auto commit 2025-04-01 16:23:28 +08:00
smallkun 0fca9c9a65 Auto commit 2025-04-01 16:16:54 +08:00
smallkun ad6ebb9fa2 Auto commit 2025-04-01 16:09:36 +08:00
smallkun e229bbbb5d Auto commit 2025-04-01 09:52:18 +08:00
smallkun dae819bf03 Auto commit 2025-03-31 20:03:24 +08:00
smallkun 984e4b5848 Auto commit 2025-03-31 19:37:23 +08:00
smallkun 2c6fa871fd Auto commit 2025-03-31 18:23:49 +08:00
smallkun 4afd009240 Auto commit 2025-03-31 18:13:34 +08:00
smallkun 7c1ff398ef Auto commit 2025-03-31 18:07:50 +08:00
smallkun b555d546f3 Auto commit 2025-03-31 13:06:12 +08:00
smallkun 7a89b6c6bd Auto commit 2025-03-30 22:00:18 +08:00
smallkun ca908905f0 Auto commit 2025-03-30 21:57:13 +08:00
smallkun e98ec49be5 Auto commit 2025-03-30 21:36:26 +08:00
smallkun 562f6156ce Auto commit 2025-03-30 19:25:28 +08:00
smallkun 12172b99ca Auto commit 2025-03-30 19:23:53 +08:00
smallkun 0f66c6b6d8 Auto commit 2025-03-30 14:20:49 +08:00
smallkun 631b95b9a1 Auto commit 2025-03-30 14:16:08 +08:00
smallkun dba08dadf4 Auto commit 2025-03-30 14:15:36 +08:00
smallkun ee5bf925ef Auto commit 2025-03-30 14:15:19 +08:00
smallkun 36a2f799e1 Auto commit 2025-03-30 14:13:39 +08:00
smallkun 9050c876b1 Auto commit 2025-03-30 14:11:55 +08:00
smallkun 1101eebe94 Auto commit 2025-03-28 10:38:36 +08:00
smallkun 3fd783abc5 Auto commit 2025-03-28 10:35:45 +08:00
smallkun 67e45ace21 Auto commit 2025-03-28 09:57:33 +08:00
smallkun 05299e024a Auto commit 2025-03-28 09:57:22 +08:00
smallkun c0663bc99c Auto commit 2025-03-28 09:12:20 +08:00
smallkun 4732388b07 Auto commit 2025-03-28 09:07:47 +08:00
smallkun 2a43e05b5f Auto commit 2025-03-28 08:36:03 +08:00
smallkun 5f169e30ac Auto commit 2025-03-28 08:32:24 +08:00
smallkun c4547a80fc Auto commit 2025-03-28 08:15:20 +08:00
smallkun d06b6fc13d Auto commit 2025-03-28 08:06:46 +08:00
smallkun 195f784173 Auto commit 2025-03-27 18:25:58 +08:00
smallkun abfd593f38 Auto commit 2025-03-27 16:05:58 +08:00
smallkun 542dd24e8d Merge branch 'main' of git.smallkun.cn:smallkun/class-notes 2025-03-27 08:00:02 +08:00
smallkun 9aa26a9fbe Auto commit 2025-03-27 07:54:53 +08:00
smallkun cc59f1a38b Auto commit 2025-03-26 09:18:31 +08:00
smallkun 947c7e78d2 Auto commit 2025-03-26 09:17:09 +08:00
smallkun 0ed3a59e2c Auto commit 2025-03-26 09:14:45 +08:00
smallkun 932fcc500c Auto commit 2025-03-26 09:07:14 +08:00
smallkun be5497370f Auto commit 2025-03-26 08:50:26 +08:00
smallkun ba7a5971be Auto commit 2025-03-26 08:47:15 +08:00
smallkun eaa1811ce7 Auto commit 2025-03-25 19:00:16 +08:00
smallkun 0699f7825b Auto commit 2025-03-25 09:44:29 +08:00
smallkun 537578994c Auto commit 2025-03-25 09:38:23 +08:00
smallkun 57e8628eec Auto commit 2025-03-25 08:35:44 +08:00
smallkun 6b086283b9 Auto commit 2025-03-25 08:31:24 +08:00
smallkun eb6a1ba10c Auto commit 2025-03-25 08:26:45 +08:00
smallkun 85aedd7dcf Auto commit 2025-03-24 20:07:56 +08:00
smallkun 4ebb1c8c83 Auto commit 2025-03-24 19:59:35 +08:00
smallkun 9a03816526 Auto commit 2025-03-24 19:51:23 +08:00
smallkun 1455f339be Auto commit 2025-03-24 19:46:42 +08:00
smallkun 21eab878bf Auto commit 2025-03-24 19:32:31 +08:00
smallkun 777fefdcef Auto commit 2025-03-24 18:55:09 +08:00
smallkun f9f35929ed Auto commit 2025-03-24 17:55:46 +08:00
smallkun 03e8200eb7 Auto commit 2025-03-24 07:50:54 +08:00
smallkun 7826824d2f Auto commit 2025-03-23 17:31:54 +08:00
smallkun 3f10d8ce73 Auto commit 2025-03-23 17:14:21 +08:00
smallkun ce7fcd525a Auto commit 2025-03-23 17:12:25 +08:00
smallkun b42341556b Auto commit 2025-03-23 17:09:40 +08:00
smallkun 04dfcd275e Auto commit 2025-03-23 00:58:09 +08:00
smallkun 8333736ef2 Auto commit 2025-03-22 22:31:45 +08:00
smallkun 2fd8dd0574 Auto commit 2025-03-22 22:30:16 +08:00
smallkun 1697d05c41 Auto commit 2025-03-22 22:29:36 +08:00
smallkun ef57fdc6da Auto commit 2025-03-22 20:08:03 +08:00
smallkun fb7ce8d575 Auto commit 2025-03-22 20:01:54 +08:00
smallkun 72d7281a50 Auto commit 2025-03-22 19:59:05 +08:00
smallkun 2e57bf8a24 Auto commit 2025-03-22 19:55:39 +08:00
smallkun 8da3011a4f Auto commit 2025-03-22 19:50:42 +08:00
smallkun f6f91c0fd4 Auto commit 2025-03-22 19:49:55 +08:00
smallkun 92bbbfb089 Auto commit 2025-03-22 19:15:32 +08:00
smallkun 281083bf85 Auto commit 2025-03-21 10:34:07 +08:00
smallkun 448f49d644 Auto commit 2025-03-21 09:38:42 +08:00
smallkun 727db1bb4a Auto commit 2025-03-21 09:35:23 +08:00
smallkun fbb09280fd Auto commit 2025-03-21 09:34:54 +08:00
smallkun b030ae136a Auto commit 2025-03-21 09:29:19 +08:00
smallkun a3837c3a77 Auto commit 2025-03-21 09:18:10 +08:00
smallkun ce0f22d5f5 Auto commit 2025-03-21 09:16:48 +08:00
smallkun 37fccb1898 Auto commit 2025-03-21 08:55:39 +08:00
smallkun 5072cd79b1 Auto commit 2025-03-21 08:51:50 +08:00
smallkun 2cafec9ae9 Auto commit 2025-03-21 08:48:40 +08:00
smallkun 983e28df10 Auto commit 2025-03-21 08:45:56 +08:00
smallkun 37f68f467b Auto commit 2025-03-21 08:25:06 +08:00
smallkun 68e4508eaf Auto commit 2025-03-20 20:00:14 +08:00
smallkun 6aa71ed621 Auto commit 2025-03-20 19:47:42 +08:00
smallkun 02788e2bb2 Auto commit 2025-03-20 19:41:17 +08:00
smallkun 95aa201cf4 Auto commit 2025-03-20 19:37:29 +08:00
smallkun 26b0159c32 Auto commit 2025-03-20 19:29:28 +08:00
smallkun 6733da3ec5 Auto commit 2025-03-20 19:11:16 +08:00
smallkun 1b42d49ba9 Auto commit 2025-03-20 18:57:01 +08:00
smallkun 4cf78065f1 Auto commit 2025-03-20 16:55:24 +08:00
smallkun da1fcd8e75 Auto commit 2025-03-20 16:54:53 +08:00
smallkun 8fa209f213 Auto commit 2025-03-20 16:47:57 +08:00
smallkun 5d16a365de Auto commit 2025-03-20 16:47:18 +08:00
smallkun 077f0330f5 Auto commit 2025-03-20 16:46:44 +08:00
smallkun 43b718db0c Auto commit 2025-03-20 16:45:59 +08:00
smallkun a192d96e71 Auto commit 2025-03-20 16:45:10 +08:00
smallkun 7e85346487 Auto commit 2025-03-20 16:42:33 +08:00
smallkun a19a2490e0 Auto commit 2025-03-20 16:36:24 +08:00
smallkun bf07420a5e Auto commit 2025-03-20 16:33:58 +08:00
smallkun d9e06991e9 Auto commit 2025-03-20 16:31:34 +08:00
smallkun 49853d7338 Auto commit 2025-03-20 14:54:00 +08:00
smallkun 2be46d87e0 Auto commit 2025-03-20 14:53:26 +08:00
smallkun 297f2784fb 2025-03-20 2025-03-20 11:23:46 +08:00
smallkun 2f7f806aab 2025-03-20 2025-03-20 11:21:09 +08:00
smallkun 72b6014ddf 2025-03-20 2025-03-20 11:01:11 +08:00
smallkun caa10b19b2 2025-03-20 2025-03-20 10:47:49 +08:00
smallkun cbf371e29d 2025-03-20 2025-03-20 10:45:11 +08:00
smallkun 5e39adead8 2025-03-20 2025-03-20 10:33:39 +08:00
smallkun 6b6d78b340 2025-03-20 2025-03-20 10:29:51 +08:00
smallkun 525c0edd1d Auto commit 2025-03-19 19:15:27 +08:00
smallkun 53224e1642 Auto commit 2025-03-19 08:00:31 +08:00
smallkun 72ad4426fe Auto commit 2025-03-19 07:59:01 +08:00
smallkun df4fea3437 Auto commit 2025-03-18 19:41:55 +08:00
smallkun 8b030d5a28 Auto commit 2025-03-18 19:12:14 +08:00
smallkun 721a9d8fb7 Auto commit 2025-03-18 18:51:27 +08:00
smallkun f93fce1ea6 Auto commit 2025-03-18 18:23:20 +08:00
smallkun 4b5e81f1b3 Auto commit 2025-03-18 17:19:54 +08:00
smallkun 55230c94e4 Auto commit 2025-03-18 09:48:39 +08:00
smallkun a580bebc74 Auto commit 2025-03-18 09:23:10 +08:00
smallkun 31af716c23 Auto commit 2025-03-18 09:18:30 +08:00
smallkun 09d0f90697 Auto commit 2025-03-18 08:52:39 +08:00
smallkun adb07f27c5 Auto commit 2025-03-18 08:37:39 +08:00
smallkun 152541650a Auto commit 2025-03-18 08:30:48 +08:00
smallkun 777ac955d0 Auto commit 2025-03-17 19:57:04 +08:00
smallkun d76940406d Auto commit 2025-03-17 19:47:22 +08:00
smallkun 86d4341146 Auto commit 2025-03-17 19:31:35 +08:00
smallkun d2970d183d Auto commit 2025-03-17 18:51:31 +08:00
smallkun cfdebb17f7 Auto commit 2025-03-17 18:50:51 +08:00
smallkun 1843d42e7e Auto commit 2025-03-16 01:26:23 +08:00
smallkun fd10dcce9e Auto commit 2025-03-16 01:19:31 +08:00
smallkun fb31fcc8c7 Auto commit 2025-03-15 23:14:59 +08:00
smallkun 4e10137543 Auto commit 2025-03-15 23:03:03 +08:00
smallkun 5f5abd6f79 Auto commit 2025-03-15 22:10:41 +08:00
smallkun 8a715c2f80 Auto commit 2025-03-15 22:07:07 +08:00
smallkun 08685dda81 Auto commit 2025-03-14 22:28:06 +08:00
smallkun bf3450efd7 Auto commit 2025-03-14 21:46:52 +08:00
smallkun ade0d7fa4b Auto commit 2025-03-14 21:36:55 +08:00
smallkun 6f7f7f2892 Auto commit 2025-03-14 21:36:07 +08:00
smallkun 3fc5a99e37 Auto commit 2025-03-14 12:14:58 +08:00
smallkun f10b80e114 Auto commit 2025-03-14 11:18:41 +08:00
smallkun baf429e8a2 Auto commit 2025-03-14 09:56:37 +08:00
smallkun 1ba7f30de6 Auto commit 2025-03-14 09:36:27 +08:00
smallkun 88350396ba Auto commit 2025-03-14 09:32:00 +08:00
smallkun 4958a07e62 Auto commit 2025-03-14 09:06:09 +08:00
smallkun c2fd89cd97 Auto commit 2025-03-14 08:53:36 +08:00
smallkun d7bb147d7f Auto commit 2025-03-14 08:46:52 +08:00
smallkun f2edb6f1f4 Auto commit 2025-03-14 08:18:40 +08:00
smallkun 2ae0682fa6 Auto commit 2025-03-14 08:15:19 +08:00
smallkun ae9579fe10 Auto commit 2025-03-14 07:59:56 +08:00
smallkun 4df646d4cf Auto commit 2025-03-14 07:55:53 +08:00
smallkun cd6b19e43c Auto commit 2025-03-13 16:46:35 +08:00
smallkun d198c8044c Auto commit 2025-03-11 08:27:21 +08:00
smallkun ffbffcdfc8 Auto commit 2025-03-10 20:07:09 +08:00
smallkun 4549e5412c Auto commit 2025-03-10 19:57:37 +08:00
smallkun 7b67a5fe21 Auto commit 2025-03-10 19:10:36 +08:00
smallkun 634e5a21fb Auto commit 2025-03-10 19:07:30 +08:00
smallkun 64c22c4d2f Auto commit 2025-03-10 18:59:05 +08:00
smallkun bfcf16acfa Auto commit 2025-03-10 18:53:27 +08:00
smallkun 246399c0c7 Auto commit 2025-03-09 21:31:44 +08:00
smallkun 116db0da21 Auto commit 2025-03-07 11:34:49 +08:00
smallkun 232d23ceca Auto commit 2025-03-07 10:07:40 +08:00
smallkun 70d5054036 Auto commit 2025-03-07 10:01:02 +08:00
smallkun 8c0d6360a2 Auto commit 2025-03-07 09:53:57 +08:00
smallkun fe970ef1a1 Auto commit 2025-03-07 09:31:53 +08:00
smallkun 13abb8ed50 Auto commit 2025-03-07 00:00:47 +08:00
smallkun eaaf651831 Auto commit 2025-03-06 23:55:54 +08:00
smallkun 3dae5b6d37 2025-03-06 2025-03-06 23:49:18 +08:00
smallkun 533f6eabc4 Auto commit 2025-03-06 23:47:59 +08:00
smallkun d12a28496d Auto commit 2025-03-06 22:46:33 +08:00
smallkun 4e21fb0e95 Auto commit 2025-03-06 22:45:36 +08:00
smallkun a86c4778f8 Auto commit 2025-03-06 22:45:14 +08:00
smallkun 5deb7de5b9 Auto commit 2025-03-06 21:56:21 +08:00
smallkun fd1b4626a6 Auto commit 2025-03-06 21:44:05 +08:00
smallkun b7c041bb94 2025-03-06 2025-03-06 20:00:31 +08:00
smallkun bbedce7b34 2025-03-06 2025-03-06 19:58:58 +08:00
smallkun 5f28bf3ec9 Auto commit 2025-03-06 19:56:07 +08:00
smallkun 5626077db1 Auto commit 2025-03-06 17:37:07 +08:00
smallkun 1f7190eff5 2025-03-06 2025-03-06 12:48:09 +08:00
smallkun 9229598107 Auto commit 2025-03-06 12:46:40 +08:00
smallkun 43a25c48b0 Auto commit 2025-03-05 09:11:17 +08:00
smallkun 29925804ff Auto commit 2025-03-05 09:07:22 +08:00
smallkun 783148afe6 Auto commit 2025-03-05 08:54:50 +08:00
smallkun 3a32020d4e Auto commit 2025-03-05 08:49:26 +08:00
smallkun c82388d6b2 Auto commit 2025-03-05 08:44:20 +08:00
smallkun 506ac8cc25 Auto commit 2025-03-04 23:18:10 +08:00
smallkun b535bc9dae Auto commit 2025-03-04 22:51:38 +08:00
smallkun 02627c7840 2025-03-04 2025-03-04 22:34:39 +08:00
smallkun ecef67c3a5 2025-03-04 2025-03-04 22:33:39 +08:00
smallkun 2491d0e09c Auto commit 2025-03-04 22:18:35 +08:00
smallkun 01227d38ab Auto commit 2025-03-04 22:16:00 +08:00
smallkun ec68bc0763 Auto commit 2025-03-04 20:10:05 +08:00
smallkun b6af2f583e Auto commit 2025-03-04 09:21:43 +08:00
smallkun 29d62ac5fe Auto commit 2025-03-04 08:56:57 +08:00
smallkun 1360a5ff09 Auto commit 2025-03-04 08:06:23 +08:00
smallkun a4ab6c3031 Auto commit 2025-03-04 08:00:29 +08:00
smallkun c05eef2b12 Auto commit 2025-02-28 11:46:50 +08:00
smallkun de4844ecad Auto commit 2025-02-28 11:29:41 +08:00
smallkun 7fb72c827d Auto commit 2025-02-28 10:49:20 +08:00
smallkun 1a337cdb21 Auto commit 2025-02-28 10:29:56 +08:00
smallkun 77130d67f9 Auto commit 2025-02-28 09:57:16 +08:00
smallkun b66b096327 Auto commit 2025-02-28 09:53:19 +08:00
smallkun 23fb17e13c Auto commit 2025-02-28 09:26:27 +08:00
smallkun 5b4d574902 Auto commit 2025-02-28 09:25:33 +08:00
smallkun dcf8569b07 Auto commit 2025-02-28 09:15:39 +08:00
smallkun 0b308fc718 Auto commit 2025-02-28 08:52:59 +08:00
smallkun a3a4f6edea Auto commit 2025-02-28 08:51:47 +08:00
smallkun 6c863dd1ce Merge branch 'main' of git.smallkun.cn:smallkun/class-notes 2025-02-28 08:41:57 +08:00
smallkun ff53142ba1 Auto commit 2025-02-28 08:41:06 +08:00
smallkun bc252f8f6c Auto commit 2025-02-27 23:36:28 +08:00
smallkun 5854a8189c Auto commit 2025-02-27 23:15:51 +08:00
smallkun ae9af0c5da Auto commit 2025-02-27 20:06:15 +08:00
smallkun 3a41de0e49 Auto commit 2025-02-27 19:38:17 +08:00
smallkun ee576351d9 Auto commit 2025-02-27 19:27:28 +08:00
smallkun 25cbe06f6c Auto commit 2025-02-27 19:27:03 +08:00
smallkun 22b99cb301 Auto commit 2025-02-27 19:24:55 +08:00
smallkun 71ea2b0d21 Auto commit 2025-02-27 18:44:58 +08:00
smallkun 5859485f29 update 2025-02-27 18:35:25 +08:00
smallkun 621b846797 Auto commit 2025-02-27 17:41:29 +08:00
smallkun 522e2388ca Auto commit 2025-02-27 17:40:50 +08:00
236 changed files with 66444 additions and 2067 deletions
Binary file not shown.
@@ -0,0 +1,14 @@
#include <stdio.h>
int main(){
int x;
while(1){
scanf("%d", &x);
if(x == 0){
break;
}
printf("%d:%s\n", x, (x%5==0&&x%7==0?"Yes":"No"));
}
return 0;
}
@@ -0,0 +1,17 @@
#include <stdio.h>
int main(){
int i, j, k;
for(i=0;i<=3;i++){
for(j=1;j<=5;j++){
for(k=0;k<=6;k++){
if(i+j+k==8){
printf("ºì:%d °×:%d ºÚ:%d\n", i, j, k);
}
}
}
}
return 0;
}
@@ -0,0 +1,19 @@
#include <stdio.h>
int main(){
int num, n=2, first = 1;
scanf("%d", &num);
printf("%d=",num);
while(num > 1){
if(num%n==0){
first?printf("%d", n):printf("*%d", n);
first=0;
num/=n;
}else{
n++;
}
}
return 0;
}
@@ -0,0 +1,21 @@
#include <stdio.h>
int main(){
int num[30], i, j;
float result[6];
for(i=0;i<30;i++){
num[i] = 2+2*i;
}
for(i=0;i<30;i+=5){
result[i/5] = (num[i]+ num[i+1] + num[i+2] + num[i+3] + num[i+4])/5.0;
}
for(i=0;i<6;i++){
printf("%.2f ", result[i]);
}
printf("\n");
return 0;
}
@@ -0,0 +1,39 @@
#include <stdio.h>
int fib(int n){
if(n== 0 || n==1){
return 1;
}
return fib(n-1) + fib(n-2);
}
int main(){
int num[15], i;
for(i=0;i<15;i++){
num[i] = fib(i);
}
for(i=0;i<15;i++){
printf("%d ", num[i]);
}
printf("\n");
return 0;
}
/*
int main(){
int num[15] = {1, 1}, i;
for(i=2;i<15;i++){
num[i] = num[i-1] + num[i-2];
}
for(i=0;i<15;i++){
printf("%d ", num[i]);
}
printf("\n");
return 0;
}
*/
@@ -0,0 +1,30 @@
#include <stdio.h>
#include <string.h>
int main(){
char a[200], b[200];//定义两个字符数组用来读取字符串a和b
char *p, *q;//定义两个指针 分别存储字符串a和字符串b的首地址
gets(a);
gets(b);//从控制台获取输入
if(strlen(b) > 5){
b[5] = '\0';
}//判定字符串是否大于5 如果大于5 则将第六个元素改成结束符
p = a;//p指向a的首地址
q = b;//q指向b的首地址
while(*p != '\0'){//找到a结束符位置的地址
p++;
}
//从b的第一个元素开始赋值到a中
while(*q != '\0'){
*p++ = *q++;
}
*p = '\0';//标记结束符
printf("a=%s\n", a);
printf("b=%s\n", b);
//srand((unsigned)time(NULL));
return 0;
}
@@ -0,0 +1,17 @@
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(){
int num[10], i;
srand((unsigned)time(NULL));
for(i=0;i<10;i++){
num[i] = rand()%101;
printf("%d ", num[i]);
}
printf("\n");
return 0;
}
@@ -0,0 +1,25 @@
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h> //里面定义了基本数据类型的最大值和最小值
int main(){
int num[3][4], i, j, min=INT_MAX, i_index, j_index;
srand((unsigned)time(NULL));
for(i=0;i<3;i++){
for(j=0;j<4;j++){
num[i][j] = rand()%101;
printf("%2d ", num[i][j]);
if(num[i][j] < min){
min = num[i][j];
i_index = i;
j_index = j;
}
}
printf("\n");
}
printf("min=%d i=%d j=%d\n", min, i_index, j_index);
return 0;
}
@@ -0,0 +1,54 @@
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
/*
1 2 3 |6
4 5 6 |15
7 8 9 |24
-------------
12 15 18
*/
void getSum(int array[100][100], int n, int m){
int i, j, sum;
for(i=0;i<n;i++){
sum = 0;
for(j=0;j<m;j++){
printf("%-5d ", array[i][j]);
sum += array[i][j];
}
printf("| %-5d\n", sum);
}
for(j=0;j<m;j++){
printf("------");
}
printf("\n");
for(j=0;j<m;j++){//列的下标
sum =0;
for(i=0;i<n;i++){//行的下标
sum += array[i][j];
}
printf("%-5d ", sum);
}
printf("\n");
}
int main(){
int n, m, i, j;//n为行数 m为列数
int array[100][100] = {0};
printf("请输入行数和列数:");
scanf("%d %d", &n, &m);
srand((unsigned)time(NULL));
for(i=0;i<n;i++){
for(j=0;j<m;j++){
array[i][j] = rand()%100;
}
}
getSum(array, n, m);
return 0;
}
@@ -0,0 +1,25 @@
#include <stdio.h>
void change(char *p){
//alex apple
*p++ -= 32;//a-> -32 ->A
while(*p != '#'){
if(*(p-1) == ' '){
*p -= 32;
}
p++;
}
*p = '\0';
}
int main(){
char str[1024];
gets(str);//读取一行字符串 回车判定结束
change(str);
puts(str);
return 0;
}
@@ -0,0 +1,30 @@
#include <stdio.h>
//Ãݴη½
int power(int n){
int s = 1, i;
for(i=1;i<=n;i++){
s *= 2;
}
return s;
}
//½×³Ë
int factorial(int n){
int s = 1, i;
for(i=1;i<=n;i++){//1~n
s*=i;
}
return s;
}
int main(){
int n, i, s = 0;
scanf("%d", &n);
for(i=1;i<=n;i++){
s += power(i) * factorial(i);
}
printf("%d\n", s);
return 0;
}
@@ -0,0 +1,25 @@
#include <stdio.h>
int main(){
int a[10], b[10];
int i;
int *p, *q;
for(i=0, p=a;i<10;i++){
scanf("%d", p++);
}
for(i=0, p=a, q=b;i<10;i++){
if(*p%2==0){
*q++=*p;
}
p++;
}
for(i=0, p=b;i<q-b;i++){
printf("%d ", *p++);
}
printf("\n");
return 0;
}
@@ -0,0 +1,23 @@
#include <stdio.h>
/*
1 2 3 4 5 6 7 8 9 10
1 3 4 5 6 7 8 9 10
*/
int main(){
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int n = 10;
int i;
int *p, *q;
p = a+1;
q = a+2;
for(i=0;i<8;i++){//用来控制循环的次数
*p++ = *q++;
}
n--;
for(i=0;i<n;i++){
printf("%d ", *(a+i));
}
printf("\n");
return 0;
}
@@ -0,0 +1,19 @@
#include <stdio.h>
int main(){
char str[] = "AbcDEfg";
char *p = str;
while(*p != '\0'){
if(*p >= 'a' && *p <= 'z'){
*p -= 32;
}else{
*p += 32;
}
p++;
}
puts(str);
return 0;
}
@@ -0,0 +1,23 @@
#include <stdio.h>
#include <string.h>
int main(){
char str[5][20];
char (*p)[20], (*max)[20];//数据类型 (*变量名)[长度];数组指针
int i;
for(i=0, p =str;i<5;i++){
scanf("%s", p++);
}
max = p;
for(i=1, p =str+1;i<5;i++){
if(strcmp(*p, *max)){
max = p;
}
p++;
}
printf("max = %s\n", max);
return 0;
}
@@ -0,0 +1,11 @@
#include <stdio.h>
#define MAXD(x, y) (x>y?x:y)
int main(){
int a, b;
scanf("%d %d", &a, &b);
//(1>2?1:2) 将MAXD替换成三目运算符
printf("%d \n", MAXD(a, b));
return 0;
}
@@ -0,0 +1,11 @@
#include <stdio.h>
#define f(n) (n%5==0 && n%7==0?"能被整除\n":"不能被整除\n")
int main(){
//#define 指令 语句序列 会在语句序列中将所有参数替换成传入的
int num;
scanf("%d", &num);
puts(f(num));
return 0;
}
@@ -0,0 +1,21 @@
#include <stdio.h>
#define CHANGE 0 //1代表打印密文 0明文
//! Ctrl + .注释
int main(){
char str[100], i=0;
scanf("%s", str);
#if CHANGE
while(str[i] != '\0'){
if(str[i] >= 'a' && str[i] <= 'y' || str[i] >= 'A' && str[i] <= 'Y' ){
str[i]++;
}else if(str[i] == 'z' || str[i] == 'Z'){
str[i]-=25;
}
i++;
}
#endif
puts(str);
return 0;
}
@@ -0,0 +1,33 @@
#include <stdio.h>
typedef struct student{
int num;
char name[20];
float socre[3];
}student;
//student 作为一个类型
//如果不写typedef则结构体类型为 struct student
void output(student stuList[5]){
int i;
for(i=0;i<5;i++){
printf("%d\t%s\t%f\t%f\t%f\n", stuList[i].num, stuList[i].name, stuList[i].socre[0],
stuList[i].socre[1], stuList[i].socre[2]);
}
}
void input(student stuList[5]){
int i;
for(i=0;i<5;i++){
scanf("%d %s %f %f %f", &stuList[i].num, stuList[i].name, &stuList[i].socre[0],
&stuList[i].socre[1], &stuList[i].socre[2]);
}
}
int main(){
student stuList[5];//定义了一个结构体数组里面可以容纳5个结构体变量
input(stuList);
output(stuList);
return 0;
}
@@ -0,0 +1,13 @@
#include <stdio.h>
typedef struct score{
float medScore;
float endScore;
}score;
int main(){
score s;
scanf("%f %f", &s.medScore, &s.endScore);
printf("avg=%.2f\n", (s.medScore + s.endScore)/2);
return 0;
}
@@ -0,0 +1,18 @@
#include <stdio.h>
int main(){
FILE *in, *out;
char str[100];
in = fopen("file1.c", "r");//r:只读
out = fopen("file2.c", "w");//w:覆盖
while(fgets(str, 100, in)){//fgets每次从文件获取一行并存储到str中
puts(str);//使用控制台输出
fputs(str, out);//向file2.c输出
}
fclose(in);//关闭文件指针
fclose(out);
return 0;
}
@@ -0,0 +1,19 @@
#include <stdio.h>
int main(){
FILE *fp;
char ch;
int count=0;
fp = fopen("letter.txt", "r");
while((ch=fgetc(fp)) != EOF){
if(ch == 'c'){
count++;
}
}
printf("c个数为:%d\n", count);
fclose(fp);//关闭文件指针
return 0;
}
@@ -0,0 +1,20 @@
#include <stdio.h>
int main(){
char str[100];
char *p = str;
FILE *fp;
fp = fopen("test.dat", "w");
gets(str);
while(*p != '\0'){
if(*p >= 'a' && *p <= 'z'){
*p-=32;
}
p++;
}
fputs(str, fp);
fclose(fp);
return 0;
}
+9
View File
@@ -0,0 +1,9 @@
#include <stdio.h>
int main(){
return 0;
}
+9
View File
@@ -0,0 +1,9 @@
#include <stdio.h>
int main(){
return 0;
}
@@ -0,0 +1 @@
ccadfadsfasfadsfafa
+1
View File
@@ -0,0 +1 @@
ADFADFAAAFDAFDSFSDF
+685 -1
View File
@@ -361,6 +361,23 @@ int main(){
![image-20250220231027969](https://yp.smallkun.cn/markdown/image-20250220231027969.png!compress) ![image-20250220231027969](https://yp.smallkun.cn/markdown/image-20250220231027969.png!compress)
```c ```c
#include <stdio.h>
int main(){
int i, j, k;
for(i=0;i<=3;i++){
for(j=1;j<=5;j++){
for(k=0;k<=6;k++){
if(i+j+k==8){
printf("红:%d 白:%d 黑:%d\n", i, j, k);
}
}
}
}
return 0;
}
``` ```
### 循环结构-9 ### 循环结构-9
@@ -368,6 +385,25 @@ int main(){
![image-20250220231034218](https://yp.smallkun.cn/markdown/image-20250220231034218.png!compress) ![image-20250220231034218](https://yp.smallkun.cn/markdown/image-20250220231034218.png!compress)
```c ```c
#include <stdio.h>
int main(){
int num, n=2, first = 1;
scanf("%d", &num);
printf("%d=",num);
while(num > 1){
if(num%n==0){
first?printf("%d", n):printf("*%d", n);
first=0;
num/=n;
}else{
n++;
}
}
return 0;
}
``` ```
### 循环结构-10 ### 循环结构-10
@@ -375,6 +411,20 @@ int main(){
![image-20250220231039716](https://yp.smallkun.cn/markdown/image-20250220231039716.png!compress) ![image-20250220231039716](https://yp.smallkun.cn/markdown/image-20250220231039716.png!compress)
```c ```c
#include <stdio.h>
int main(){
int x;
while(1){
scanf("%d", &x);
if(x == 0){
break;
}
printf("%d:%s\n", x, (x%5==0&&x%7==0?"Yes":"No"));
}
return 0;
}
``` ```
--- ---
@@ -385,48 +435,682 @@ int main(){
![image-20250220231426147](https://yp.smallkun.cn/markdown/image-20250220231426147.png!compress) ![image-20250220231426147](https://yp.smallkun.cn/markdown/image-20250220231426147.png!compress)
```c
#include <stdio.h>
int main(){
int num[30], i, j;
float result[6];
for(i=0;i<30;i++){
num[i] = 2+2*i;
}
for(i=0;i<30;i+=5){
result[i/5] = (num[i]+ num[i+1] + num[i+2] + num[i+3] + num[i+4])/5.0;
}
for(i=0;i<6;i++){
printf("%.2f ", result[i]);
}
printf("\n");
return 0;
}
```
### 数组-2 ### 数组-2
![image-20250220231434409](https://yp.smallkun.cn/markdown/image-20250220231434409.png!compress) ![image-20250220231434409](https://yp.smallkun.cn/markdown/image-20250220231434409.png!compress)
```c
#include <stdio.h>
int fib(int n){
if(n== 0 || n==1){
return 1;
}
return fib(n-1) + fib(n-2);
}
int main(){
int num[15], i;
for(i=0;i<15;i++){
num[i] = fib(i);
}
for(i=0;i<15;i++){
printf("%d ", num[i]);
}
printf("\n");
return 0;
}
/*
int main(){
int num[15] = {1, 1}, i;
for(i=2;i<15;i++){
num[i] = num[i-1] + num[i-2];
}
for(i=0;i<15;i++){
printf("%d ", num[i]);
}
printf("\n");
return 0;
}
*/
```
### 数组-3 ### 数组-3
![image-20250220231441384](https://yp.smallkun.cn/markdown/image-20250220231441384.png!compress) ![image-20250220231441384](https://yp.smallkun.cn/markdown/image-20250220231441384.png!compress)
```c
#include <stdio.h>
#include <string.h>
int main(){
char a[200], b[200];//定义两个字符数组用来读取字符串a和b
char *p, *q;//定义两个指针 分别存储字符串a和字符串b的首地址
gets(a);
gets(b);//从控制台获取输入
if(strlen(b) > 5){
b[5] = '\0';
}//判定字符串是否大于5 如果大于5 则将第六个元素改成结束符
p = a;//p指向a的首地址
q = b;//q指向b的首地址
while(*p != '\0'){//找到a结束符位置的地址
p++;
}
//从b的第一个元素开始赋值到a中
while(*q != '\0'){
*p++ = *q++;
}
*p = '\0';//标记结束符
printf("a=%s\n", a);
printf("b=%s\n", b);
return 0;
}
```
### 数组-4 ### 数组-4
![image-20250220231447834](https://yp.smallkun.cn/markdown/image-20250220231447834.png!compress) ![image-20250220231447834](https://yp.smallkun.cn/markdown/image-20250220231447834.png!compress)
```c
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(){
int num[10], i;
srand((unsigned)time(NULL));
for(i=0;i<10;i++){
num[i] = rand()%101;
printf("%d ", num[i]);
}
printf("\n");
return 0;
}
```
### 数组-5 ### 数组-5
![image-20250220231704799](https://yp.smallkun.cn/markdown/image-20250220231704799.png!compress) ![image-20250220231704799](https://yp.smallkun.cn/markdown/image-20250220231704799.png!compress)
```c
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h> //里面定义了基本数据类型的最大值和最小值
int main(){
int num[3][4], i, j, min=INT_MAX, i_index, j_index;
srand((unsigned)time(NULL));
for(i=0;i<3;i++){
for(j=0;j<4;j++){
num[i][j] = rand()%101;
printf("%2d ", num[i][j]);
if(num[i][j] < min){
min = num[i][j];
i_index = i;
j_index = j;
}
}
printf("\n");
}
printf("min=%d i=%d j=%d\n", min, i_index, j_index);
return 0;
}
```
--- ---
## 函数 ## 函数
### 函数-1
![image-20250227231121624](https://yp.smallkun.cn/markdown/image-20250227231121624.png!compress)
```c
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
/*
1 2 3 |6
4 5 6 |15
7 8 9 |24
-------------
12 15 18
*/
void getSum(int array[100][100], int n, int m){
int i, j, sum;
for(i=0;i<n;i++){
sum = 0;
for(j=0;j<m;j++){
printf("%-5d ", array[i][j]);
sum += array[i][j];
}
printf("| %-5d\n", sum);
}
for(j=0;j<m;j++){
printf("------");
}
printf("\n");
for(j=0;j<m;j++){//列的下标
sum =0;
for(i=0;i<n;i++){//行的下标
sum += array[i][j];
}
printf("%-5d ", sum);
}
printf("\n");
}
int main(){
int n, m, i, j;//n为行数 m为列数
int array[100][100] = {0};
printf("请输入行数和列数:");
scanf("%d %d", &n, &m);
srand((unsigned)time(NULL));
for(i=0;i<n;i++){
for(j=0;j<m;j++){
array[i][j] = rand()%100;
}
}
getSum(array, n, m);
return 0;
}
```
### 函数-2
![image-20250227231147113](https://yp.smallkun.cn/markdown/image-20250227231147113.png!compress)
```c
#include <stdio.h>
void change(char *p){
//alex apple
*p++ -= 32;//a-> -32 ->A
while(*p != '#'){
if(*(p-1) == ' '){
*p -= 32;
}
p++;
}
*p = '\0';
}
int main(){
char str[1024];
gets(str);//读取一行字符串 回车判定结束
change(str);
puts(str);
return 0;
}
```
### 函数-3
![image-20250227231154429](https://yp.smallkun.cn/markdown/image-20250227231154429.png!compress)
```c
#include <stdio.h>
//幂次方
int power(int n){
int s = 1, i;
for(i=1;i<=n;i++){
s *= 2;
}
return s;
}
//阶乘
int factorial(int n){
int s = 1, i;
for(i=1;i<=n;i++){//1~n
s*=i;
}
return s;
}
int main(){
int n, i, s = 0;
scanf("%d", &n);
for(i=1;i<=n;i++){
s += power(i) * factorial(i);
}
printf("%d\n", s);
return 0;
}
```
## 指针 ## 指针
### 指针-1
![image-20250227231209008](https://yp.smallkun.cn/markdown/image-20250227231209008.png!compress)
```c
#include <stdio.h>
int main(){
int a[10], b[10];
int i;
int *p, *q;
for(i=0, p=a;i<10;i++){
scanf("%d", p++);
}
for(i=0, p=a, q=b;i<10;i++){
if(*p%2==0){
*q++=*p;
}
p++;
}
for(i=0, p=b;i<q-b;i++){
printf("%d ", *p++);
}
printf("\n");
return 0;
}
```
### 指针-2
![image-20250227231216409](https://yp.smallkun.cn/markdown/image-20250227231216409.png!compress)
```c
#include <stdio.h>
/*
1 2 3 4 5 6 7 8 9 10
1 3 4 5 6 7 8 9 10
*/
int main(){
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int n = 10;
int i;
int *p, *q;
p = a+1;
q = a+2;
for(i=0;i<8;i++){//用来控制循环的次数
*p++ = *q++;
}
n--;
for(i=0;i<n;i++){
printf("%d ", *(a+i));
}
printf("\n");
return 0;
}
```
### 指针-3
![image-20250227231232971](https://yp.smallkun.cn/markdown/image-20250227231232971.png!compress)
```c
#include <stdio.h>
int main(){
char str[] = "AbcDEfg";
char *p = str;
while(*p != '\0'){
if(*p >= 'a' && *p <= 'z'){
*p -= 32;
}else{
*p += 32;
}
p++;
}
puts(str);
return 0;
}
```
### 指针-4
![image-20250227231243197](https://yp.smallkun.cn/markdown/image-20250227231243197.png!compress)
```c
#include <stdio.h>
#include <string.h>
int main(){
char str[5][20];
char (*p)[20], (*max)[20];//数据类型 (*变量名)[长度];数组指针
int i;
for(i=0, p =str;i<5;i++){
scanf("%s", p++);
}
max = p;
for(i=1, p =str+1;i<5;i++){
if(strcmp(*p, *max)){
max = p;
}
p++;
}
printf("max = %s\n", max);
return 0;
}
```
## 编译预处理 ## 编译预处理
### 预处理-1
![image-20250227231302316](https://yp.smallkun.cn/markdown/image-20250227231302316.png!compress)
```c
#include <stdio.h>
#define MAXD(x, y) (x>y?x:y)
int main(){
int a, b;
scanf("%d %d", &a, &b);
//(1>2?1:2) 将MAXD替换成三目运算符
printf("%d \n", MAXD(a, b));
return 0;
}
```
### 预处理-2
![image-20250227231314793](https://yp.smallkun.cn/markdown/image-20250227231314793.png!compress)
```c
#include <stdio.h>
#define f(n) (n%5==0 && n%7==0?"能被整除\n":"不能被整除\n")
int main(){
//#define 指令 语句序列 会在语句序列中将所有参数替换成传入的
int num;
scanf("%d", &num);
puts(f(num));
return 0;
}
```
### 预处理-3
![image-20250227231325297](https://yp.smallkun.cn/markdown/image-20250227231325297.png!compress)
```c
#include <stdio.h>
#define CHANGE 0 //1代表打印密文 0明文
//! Ctrl + .注释
int main(){
char str[100], i=0;
scanf("%s", str);
#if CHANGE
while(str[i] != '\0'){
if(str[i] >= 'a' && str[i] <= 'y' || str[i] >= 'A' && str[i] <= 'Y' ){
str[i]++;
}else if(str[i] == 'z' || str[i] == 'Z'){
str[i]-=25;
}
i++;
}
#endif
puts(str);
return 0;
}
```
## 结构体 ## 结构体
### 结构体-1
![image-20250227231339018](https://yp.smallkun.cn/markdown/image-20250227231339018.png!compress)
```c
#include <stdio.h>
typedef struct student{
int num;
char name[20];
float socre[3];
}student;
//student 作为一个类型
//如果不写typedef则结构体类型为 struct student
void output(student stuList[5]){
int i;
for(i=0;i<5;i++){
printf("%d\t%s\t%f\t%f\t%f\n", stuList[i].num, stuList[i].name, stuList[i].socre[0],
stuList[i].socre[1], stuList[i].socre[2]);
}
}
int main(){
student stuList[5];//定义了一个结构体数组里面可以容纳5个结构体变量
int i;
for(i=0;i<5;i++){
scanf("%d %s %f %f %f", &stuList[i].num, stuList[i].name, &stuList[i].socre[0],
&stuList[i].socre[1], &stuList[i].socre[2]);
}
output(stuList);
return 0;
}
```
### 结构体-2
![image-20250227231421233](https://yp.smallkun.cn/markdown/image-20250227231421233.png!compress)
```c
#include <stdio.h>
typedef struct student{
int num;
char name[20];
float socre[3];
}student;
//student 作为一个类型
//如果不写typedef则结构体类型为 struct student
void output(student stuList[5]){
int i;
for(i=0;i<5;i++){
printf("%d\t%s\t%f\t%f\t%f\n", stuList[i].num, stuList[i].name, stuList[i].socre[0],
stuList[i].socre[1], stuList[i].socre[2]);
}
}
void input(student stuList[5]){
int i;
for(i=0;i<5;i++){
scanf("%d %s %f %f %f", &stuList[i].num, stuList[i].name, &stuList[i].socre[0],
&stuList[i].socre[1], &stuList[i].socre[2]);
}
}
int main(){
student stuList[5];//定义了一个结构体数组里面可以容纳5个结构体变量
input(stuList);
output(stuList);
return 0;
}
```
### 结构体-3
![image-20250227231434183](https://yp.smallkun.cn/markdown/image-20250227231434183.png!compress)
```c
#include <stdio.h>
typedef struct score{
float medScore;
float endScore;
}score;
int main(){
score s;
scanf("%f %f", &s.medScore, &s.endScore);
printf("avg=%.2f\n", (s.medScore + s.endScore)/2);
return 0;
}
```
## 文件 ## 文件
## ### 文件-1
![image-20250227231459946](https://yp.smallkun.cn/markdown/image-20250227231459946.png!compress)
```c
#include <stdio.h>
int main(){
FILE *in, *out;
char str[100];
in = fopen("file1.c", "r");//r:只读
out = fopen("file2.c", "w");//w:覆盖
while(fgets(str, 100, in)){//fgets每次从文件获取一行并存储到str中
puts(str);//使用控制台输出
fputs(str, out);//向file2.c输出
}
fclose(in);//关闭文件指针
fclose(out);
return 0;
}
```
### 文件-2
![image-20250227231509693](https://yp.smallkun.cn/markdown/image-20250227231509693.png!compress)
```c
#include <stdio.h>
int main(){
FILE *fp;
char ch;
int count=0;
fp = fopen("letter.txt", "r");
while((ch=fgetc(fp)) != EOF){
if(ch == 'c'){
count++;
}
}
printf("c个数为:%d\n", count);
fclose(fp);//关闭文件指针
return 0;
}
```
### 文件-3
![image-20250227231516025](https://yp.smallkun.cn/markdown/image-20250227231516025.png!compress)
```c
#include <stdio.h>
int main(){
char str[100];
char *p = str;
FILE *fp;
fp = fopen("test.dat", "w");
gets(str);
while(*p != '\0'){
if(*p >= 'a' && *p <= 'z'){
*p-=32;
}
p++;
}
fputs(str, fp);
fclose(fp);
return 0;
}
```
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -0,0 +1,651 @@
### 练习一
![image-20250315225248590](https://yp.smallkun.cn/markdown/image-20250315225248590.png!compress)
```sql
#(1)
CREATE DATABASE test04_Market DEFAULT CHARACTER SET utf8;
USE test04_Market;
#(2)
CREATE TABLE customers(
c_num INT(11) PRIMARY KEY AUTO_INCREMENT,
c_name VARCHAR(50),
c_contact VARCHAR(50),
c_city VARCHAR(50),
c_birth DATETIME NOT NULL
);
#(3)
#AFTER/BEFORE /
ALTER TABLE MODIFY AFTER/BEFORE ;
ALTER TABLE customers MODIFY c_contact VARCHAR(50) AFTER c_birth;
#(4)
ALTER TABLE customers MODIFY c_name VARCHAR(70);
#(5)
ALTER TABLE customers CHANGE c_contact c_phone VARCHAR(50);
#(6)
ALTER TABLE customers ADD c_gender CHAR(1);
#(7)
ALTER TABLE customers RENAME TO customers_info;
#(8)
ALTER TABLE customers_info DROP c_city;
```
![image-20250315225304324](https://yp.smallkun.cn/markdown/image-20250315225304324.png!compress)
```sql
#(1)
CREATE TABLE orders(
o_num INT(11) PRIMARY KEY AUTO_INCREMENT,
o_date DATE,
c_id INT(11),
CONSTRAINT fk_cid FOREIGN KEY(c_id) REFERENCES customers_info(c_num)
);
#(2)
#
ALTER TABLE orders DROP FOREIGN KEY orders_ibfk_1;
#
DROP TABLE orders;
```
---
### 练习二
![image-20250315225318753](https://yp.smallkun.cn/markdown/image-20250315225318753.png!compress)
![image-20250315225328264](https://yp.smallkun.cn/markdown/image-20250315225328264.png!compress)
```sql
#(1)
CREATE TABLE pet(
`name` VARCHAR(20) NOT NULL COMMENT '宠物名称',
`owner` VARCHAR(20) COMMENT '宠物主人',
species VARCHAR(20) NOT NULL COMMENT '种类',
sex CHAR(1) NOT NULL COMMENT '性别',
birth YEAR NOT NULL COMMENT '出生日期',
death YEAR COMMENT '死亡日期'
);
INSERT INTO pet()
VALUES
('Fluffy', 'Harold', 'cat', 'f', 2003, 2010),
('Claws', 'Gwen', 'cat', 'm', 2004,NULL ),
('Buffy', NULL, 'dog', 'f', 2009, NULL),
('Fang', 'Benny', 'dog', 'm', 2000, NULL),
('Bowser', 'Diane', 'dog', 'm', 2003, 2009),
('Chirpy', NULL, 'bird', 'f', 2008, NULL);
#(2)
UPDATE pet
SET `owner` = 'Kevin'
WHERE `name` = 'Fang';
#(3)
UPDATE pet
SET `owner` = 'Kevin'
WHERE `owner` IS NULL;
#(4)
DELETE FROM pet
WHERE death IS NOT NULL;
#(5)
TRUNCATE pet;
```
---
### 练习三
![image-20250315225417117](https://yp.smallkun.cn/markdown/image-20250315225417117.png!compress)
![image-20250315225431297](https://yp.smallkun.cn/markdown/image-20250315225431297.png!compress)
```sql
#1.
CREATE DATABASE test_compay DEFAULT CHARACTER SET utf8;
#2.
CREATE TABLE department(
depid INT PRIMARY KEY AUTO_INCREMENT,
depname VARCHAR(20) NOT NULL,
deinfo VARCHAR(50)
);
CREATE TABLE employee(
empid INT PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(20) NOT NULL,
sex CHAR(1) NOT NULL DEFAULT '',
title VARCHAR(20) NOT NULL,
birthday DATE NOT NULL,
depid INT,
CONSTRAINT fk_eid_did FOREIGN KEY(depid) REFERENCES department(depid)
);
CREATE TABLE salary(
empid INT,
basesalary DECIMAL(10, 2),
titleSalary DECIMAL(10, 2),
decuction DECIMAL(10, 2)
);
#3
ALTER TABLE salary ADD CONSTRAINT fk_sal_eid FOREIGN KEY(empid)
REFERENCES employee(empid) ON UPDATE CASCADE ON DELETE CASCADE;
#4
INSERT INTO department (depid, depname, deinfo)
VALUES
(111, '生产部', NULL),
(222, '销售部', NULL),
(333, '人事部', NULL),
(444, '财务部', '负责公司财务管理'),
(555, '技术部', '负责技术研发与支持'),
(666, '市场部', '负责市场推广与品牌建设'),
(777, '客服部', '负责客户服务与支持'),
(888, '采购部', '负责公司物资采购'),
(999, '法务部', '负责公司法律事务'),
(1010, '行政部', '负责公司日常行政管理'),
(1011, '研发部', '负责新产品研发'),
(1012, '培训部', '负责员工培训与发展');
INSERT INTO employee (empid, name, sex, title, birthday, depid)
VALUES
(1001, '张三', '', '高级工程师', '1975-1-1', 111),
(1002, '李四', '', '助工', '1985-1-1', 111),
(1003, '王五', '', '工程师', '1978-11-11', 222),
(1004, '赵六', '', '工程师', '1999-1-1', 222),
(1005, '陈七', '', '会计师', '1980-5-15', 444),
(1006, '刘八', '', '软件工程师', '1990-8-20', 555),
(1007, '孙九', '', '市场经理', '1985-12-25', 666),
(1008, '周十', '', '客服专员', '1992-3-10', 777),
(1009, '吴十一', '', '采购经理', '1988-7-22', 888),
(1010, '郑十二', '', '法务顾问', '1983-9-30', 999),
(1011, '王十三', '', '行政助理', '1995-4-18', 1010),
(1012, '李十四', '', '研发工程师', '1991-11-5', 1011),
(1013, '赵十五', '', '培训讲师', '1987-6-12', 1012),
(1014, '孙十六', '', '技术支持', '1993-2-14', 555),
(1015, '杨十七', '', '销售代表', '1994-8-8', 222);
INSERT INTO salary (empid, basesalary, titleSalary, decuction)
VALUES
(1001, 2200, 1100, 200),
(1002, 1200, 200, NULL),
(1003, 2900, 700, 200),
(1004, 1950, 700, 150),
(1005, 2500, 800, 100),
(1006, 3000, 1200, 250),
(1007, 2800, 1000, 200),
(1008, 1800, 300, 50),
(1009, 3200, 900, 300),
(1010, 3500, 1000, 400),
(1011, 2000, 400, 100),
(1012, 3100, 1100, 200),
(1013, 2700, 800, 150),
(1014, 2300, 700, 100),
(1015, 2600, 600, 200);
```
![image-20250315225441802](https://yp.smallkun.cn/markdown/image-20250315225441802.png!compress)
```sql
#5
SELECT e.empid, e.`name`, e.title, d.depname, s.basesalary + s.titleSalary, s.basesalary + s.titleSalary-IFNULL(s.decuction, 0)
FROM employee e, department d, salary s
WHERE e.depid = d.depid AND e.empid = s.empid;
#6
SELECT e.`name`, s.basesalary
FROM employee e, department d, salary s
WHERE e.depid = d.depid AND e.empid = s.empid AND d.depname = '销售部';
#7
SELECT *
FROM employee e
WHERe e.`name` LIKE '张%' AND TIMESTAMPDIFF(YEAR,e.birthday, NOW()) < 40;
#8
SELECT e.`name`, s.basesalary, s.titleSalary
FROM employee e, salary s
WHERE e.sex = '' AND e.empid AND s.empid;
#9
SELECT e.`name`, e.title, d.depname
FROM employee e, department d, salary s
WHERE e.depid = d.depid AND e.empid = s.empid AND s.basesalary < 2000;
#10
SELECT COUNT(*)
FROM employee;
#11
SELECT COUNT(*)
FROM department d;
#12
SELECT AVG(s.basesalary + s.titleSalary), MAX(s.basesalary + s.titleSalary), MIN(s.basesalary + s.titleSalary)
FROM employee e, salary s
WHERE e.empid = s.empid;
#13
SELECT d.depname, AVG(s.basesalary + s.titleSalary)
FROM employee e, salary s, department d
WHERE e.empid = s.empid AND e.depid = d.depid
GROUP BY d.depid;
#14
SELECT d.depname, AVG(s.basesalary + s.titleSalary) avg
FROM employee e, salary s, department d
WHERE e.empid = s.empid AND e.depid = d.depid
GROUP BY d.depid
HAVING avg<2000;
#15
SELECT e.empid, e.`name`, s.basesalary, s.titleSalary, s.decuction
FROM employee e, salary s, department d
WHERE e.empid = s.empid AND e.depid = d.depid
ORDER BY s.titleSalary, s.basesalary;
#16
SELECT e.empid, e.`name`, e.birthday,
IF(YEAR(e.birthday) < 1980, '老年',
IF(YEAR(e.birthday)< 1990, '中年', '青壮年'))
FROM employee e;
#17
SELECT e.*, depname
FROM employee e, department d
WHERE e.depid = d.depid;
#18
SELECT d.*, e.*
FROM employee e, department d
WHERE e.depid = d.depid;
#19
SELECT *
FROM employee e
WHERE e.title LIKE '%工程师%' AND e.sex = '';
#20
SELECT d.depname, e.sex, COUNT(*), AVG(s.basesalary)
FROM employee e, department d, salary s
WHERE e.depid = d.depid AND e.empid = s.empid
GROUP BY d.depid, e.sex;
```
---
### 练习四
![image-20250315225803115](https://yp.smallkun.cn/markdown/image-20250315225803115.png!compress)
![image-20250315225818026](https://yp.smallkun.cn/markdown/image-20250315225818026.png!compress)
```sql
#1
CREATE DATABASE test_school DEFAULT CHARACTER SET 'UTF8';
#2
DROP TABLE department;
CREATE TABLE department(
depNo INT(10) PRIMARY KEY COMMENT '部门号',
depName VARCHAR(50) NOT NULL COMMENT '部门名称',
depNote VARCHAR(20) COMMENT '部门备注'
);
CREATE TABLE teacher(
number INT PRIMARY KEY COMMENT '教工号',
`name` VARCHAR(30) NOT NULL COMMENT '姓名',
sex VARCHAR(4) COMMENT '性别',
birth DATE COMMENT '出生日期',
depNo INT COMMENT '部门号',
salary FLOAT COMMENT '工资',
address VARCHAR(100) COMMENT '家庭住址'
);
INSERT INTO department()
VALUES
(601, '软件技术系', '软件技术等专业'),
(602, '网络技术系', '多媒体技术等专业'),
(603, '艺术设计系', '广告艺术设计等专业'),
(604, '管理工程系', '连锁经营管理等专业');
INSERT INTO teacher()
VALUES
(2001, 'Tom', '', '1970-01-10', 602, 4500, '四川省绵阳市'),
(2002, 'Lucy', '', '1983-12-18', 601, 2500, '北京市昌平区'),
(2003, 'Mike', '', '1990-06-01', 604, 1500, '重庆市渝中区'),
(2004, 'James', '', '1980-10-20', 602, 3500, '四川省成都市'),
(2005, 'Jack', '', '1975-05-30', 603, 1200, '重庆市南岸区');
```
![image-20250315225829272](https://yp.smallkun.cn/markdown/image-20250315225829272.png!compress)
```sql
#4
SELECT *
FROM teacher;
#5
SELECT t.number '教工号', d.depName '部门名称'
FROM teacher t, department d
WHERE t.depNo = d.depNo AND t.address LIKE '%北京%';
#6
SELECT t.number, t.`name`
FROM teacher t
ORDER BY t.salary DESC
LIMIT 1;
#7
SELECT t.number, t.`name`
FROM teacher t
WHERE t.salary BETWEEN 2500 AND 4000;
#8
SELECT t.`name`, t.sex, t.salary
FROM teacher t, department d
WHERE t.depNo = d.depNo AND d.depName = '网络技术系';
```
---
### 练习五
![image-20250315230015174](https://yp.smallkun.cn/markdown/image-20250315230015174.png!compress)
```sql
-- 创建数据库并设置字符集为 utf8mb4
CREATE DATABASE test_student CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE test_student;
-- 创建表 Classes
CREATE TABLE Classes (
VARCHAR(50),
VARCHAR(50),
VARCHAR(50),
VARCHAR(10),
INT
);
-- 向表 Classes 插入数据
INSERT INTO Classes (, , , , ) VALUES
('计算机网络', '1班', '张三', '', 8),
('软件工程', '2班', '李四', '', 12),
('计算机维护', '1班', '王五', '', 9),
('计算机网络', '2班', 'LILY', '', 15),
('软件工程', '1班', '小强', '', 20),
('计算机维护', '1班', 'CoCo', '', 18);
-- 创建表 Score
CREATE TABLE Score (
VARCHAR(50),
INT,
INT,
INT
);
-- 向表 Score 插入数据
INSERT INTO Score (, , , ) VALUES
('张三', 65, 75, 98),
('李四', 87, 45, 86),
('王五', 98, 85, 65),
('LILY', 75, 86, 87),
('小强', 85, 60, 58),
('CoCo', 96, 87, 70);
-- 创建表 Records
CREATE TABLE Records (
VARCHAR(50),
VARCHAR(50)
);
-- 向表 Records 插入数据
INSERT INTO Records (, ) VALUES
('小强', '迟到'),
('小强', '事假'),
('李四', '旷课'),
('李四', '旷课'),
('李四', '迟到'),
('CoCo', '病假'),
('LILY', '事假');
```
![image-20250315230025538](https://yp.smallkun.cn/markdown/image-20250315230025538.png!compress)
```sql
#3
UPDATE score s
SET s.`` = 88
WHERE s.`` = '张三';
#4
SELECT AVG(s.``), AVG(s.``), AVG(s.``)
FROM classes c, score s
WHERE c.`` = s.`` AND c.`` = 1 AND c.`` = '计算机维护';
#5
SELECT *
FROM score s
WHERE s.`` < 60 OR s.`` < 60 OR s.`` < 60;
#6
SELECT *
FROM score s
WHERE s.`` IN (
SELECT r.``
FROM records r
GROUP BY r.``
HAVING COUNT(*) > 2
);
```
---
### 练习六
![image-20250315230057816](https://yp.smallkun.cn/markdown/image-20250315230057816.png!compress)
```sql
-- 创建数据库 test_xuankedb 并设置字符集为 utf8mb4
CREATE DATABASE test_xuankedb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE test_xuankedb;
-- 创建学生表 Student
CREATE TABLE Student (
Sn0 VARCHAR(20) PRIMARY KEY, -- 学号,主键
Sname VARCHAR(50), -- 姓名
Ssex VARCHAR(10), -- 性别
Sage INT, -- 年龄
Sdept VARCHAR(50) -- 所在系
);
-- 创建课程表 Course
CREATE TABLE Course (
Cn0 VARCHAR(20) PRIMARY KEY, -- 课程号,主键
Cname VARCHAR(100), -- 课程名
Cpn0 VARCHAR(20), -- 选修课号
Ccredit INT -- 学分
);
-- 创建成绩表 SG
CREATE TABLE SG (
Sn0 VARCHAR(20), -- 学号
Cn0 VARCHAR(20), -- 课程号
Grade INT, -- 成绩
PRIMARY KEY (Sn0, Cn0), -- 复合主键 (学号, 课程号)
FOREIGN KEY (Sn0) REFERENCES Student(Sn0), -- 外键,引用 Student 表
FOREIGN KEY (Cn0) REFERENCES Course(Cn0) -- 外键,引用 Course 表
);
INSERT INTO Student (Sno, Sname, Ssex, Sage, Sdept, Scome) VALUES
('05001', '张三', '', 20, '计算机系', '2021-09-01'),
('05002', '李四', '', 21, '数学系', '2021-09-01'),
('05003', '王五', '', 22, '计算机系', '2021-09-01'),
('05004', '李洋', '', 19, '物理系', '2021-09-01'),
('05019', '赵六', '', 20, '计算机系', '2021-09-01');
INSERT INTO Course (Cno, Cname, Cpno, Ccredit) VALUES
('1', '数据库', NULL, 4),
('2', '数学', NULL, 3),
('3', '物理', NULL, 3),
('4', '操作系统', '1', 4);
INSERT INTO SG (Sno, Cno, Grade) VALUES
('05001', '1', 85),
('05001', '2', 90),
('05002', '1', 78),
('05002', '3', 88),
('05003', '1', 92),
('05003', '4', 76),
('05004', '3', 95),
('05019', '1', 80),
('05019', '4', 85);
```
---
### 练习七
![image-20250315230113710](https://yp.smallkun.cn/markdown/image-20250315230113710.png!compress)
![image-20250315230128412](https://yp.smallkun.cn/markdown/image-20250315230128412.png!compress)
```sql
-- 创建数据库 test_library 并设置字符集为 utf8mb4
CREATE DATABASE test_library CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE test_library;
-- 创建表 press(出版社)
CREATE TABLE press (
pressid INT PRIMARY KEY, -- 出版社编号,主键
pressname VARCHAR(100), -- 出版社名称
address VARCHAR(100) -- 出版社地址
);
-- 创建表 sort(种类)
CREATE TABLE sort (
sortno INT PRIMARY KEY, -- 种类编号,主键
scount INT, -- 数量
describes VARCHAR(100) -- 描述
);
-- 创建表 book(图书)
CREATE TABLE book (
bid INT PRIMARY KEY, -- 图书编号,主键
bname VARCHAR(100), -- 图书名称
bsortno INT, -- 种类编号
pressid INT, -- 出版社编号
FOREIGN KEY (bsortno) REFERENCES sort(sortno), -- 外键,引用 sort 表
FOREIGN KEY (pressid) REFERENCES press(pressid) -- 外键,引用 press 表
);
-- 向 press 表插入数据
INSERT INTO press (pressid, pressname, address) VALUES
(100, '外研社', '上海'),
(101, '北大出版社', '北京'),
(102, '教育出版社', '北京');
-- 向 sort 表插入数据
INSERT INTO sort (sortno, scount, describes) VALUES
(11, 50, '小说'),
(12, 100, '科幻'),
(13, 100, '神话');
-- 向 book 表插入数据
INSERT INTO book (bid, bname, bsortno, pressid) VALUES
(1, '红与黑', 11, 100),
(2, '幻城', 12, 102),
(3, '希腊神话', 13, 102);
#5
SELECT b.*
FROM book b, press p
WHERE p.pressid = b.pressid AND p.pressid = 100;
#6
SELECT b.*
FROM book b, press p
WHERE p.pressid = b.pressid AND p.pressname = '外研社';
#7
SELECT *
FROM sort s
WHERE s.scount > 100;
#8
SELECT p.*
FROM book b, press p
WHERE p.pressid = b.pressid
GROUP BY b.pressid
HAVING COUNT(*) = (
SELECT COUNT(*)
FROM book b, press p
WHERE p.pressid = b.pressid
GROUP BY b.pressid
ORDER BY COUNT(*) DESC
LIMIT 1
);
```
---
### 练习八
![image-20250315230214156](https://yp.smallkun.cn/markdown/image-20250315230214156.png!compress)
![image-20250315230227129](https://yp.smallkun.cn/markdown/image-20250315230227129.png!compress)
```sql
-- 创建数据库 test_tour 并设置字符集为 utf8mb4
CREATE DATABASE test_tour CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE test_tour;
-- 创建表 agency(旅行社表)
CREATE TABLE agency (
id INT PRIMARY KEY, -- 旅行社编号,主键
name VARCHAR(100) NOT NULL, -- 旅行社名
address VARCHAR(100) NOT NULL, -- 旅行社地址
areaid INT -- 所属区域编号
);
-- 创建表 travel(旅行线路表)
CREATE TABLE travel (
tid INT PRIMARY KEY, -- 旅行线路编号,主键
time VARCHAR(50) NOT NULL, -- 所需时间
position VARCHAR(100) NOT NULL, -- 目的地
money FLOAT, -- 花费
aid INT NOT NULL, -- 所属旅行社编号
count INT, -- 报名人数
FOREIGN KEY (aid) REFERENCES agency(id) -- 外键,引用 agency 表
);
-- 向 agency 表插入数据
INSERT INTO agency (id, name, address) VALUES
(101, '青年旅行社', '北京海淀'),
(102, '天天旅行社', '天津海院');
-- 向 travel 表插入数据
INSERT INTO travel (tid, time, position, money, aid, count) VALUES
(1, '5天', '八达岭', 3000, 101, 10),
(2, '7天', '水长城', 5000, 101, 14),
(3, '8天', '水长城', 6000, 102, 11);
#4
SELECT a.*
FROM travel t, agency a
WHERE t.aid =a.id
GROUP BY a.id
HAVING COUNT(*) = (
SELECT COUNT(*)
FROM travel t, agency a
WHERE t.aid =a.id
GROUP BY a.id
ORDER BY COUNT(*) DESC
LIMIT 1
);
#5
SELECT t.*
FROM travel t
WHERE t.count = (
SELECT t.count
FROM travel t
ORDER BY t.count DESC
LIMIT 1
);
#6
SELECT *
FROM travel t
WHERE t.money < 5000;
#7
SELECT a.`name`
FROM travel t, agency a
WHERE t.aid =a.id AND t.money = (
SELECT t.money
FROM travel t, agency a
WHERE t.aid =a.id
ORDER BY t.money DESC
LIMIT 1
);
#8
SELECT SUM(t.time)
FROM travel t, agency a
WHERE t.aid =a.id AND a.`name` = '青年旅行社';
```
+12 -3
View File
@@ -584,11 +584,20 @@ TIMESTAMPDIFF(YEAR,s.birth,NOW())-1, TIMESTAMPDIFF(YEAR,s.birth,NOW()))
FROM students s; FROM students s;
#42. #42.
SELECT *
FROM students s
WHERE WEEKOFYEAR(s.birth) = WEEKOFYEAR(NOW());
#43. #43.
SELECT *
FROM students s
WHERE WEEKOFYEAR(s.birth) = WEEKOFYEAR(NOW()) + 1;
#44. #44.
SELECT *
FROM students s
WHERE MONTH(s.birth) = MONTH(NOW());
#45. #45.
SELECT *
FROM students s
WHERE MONTH(s.birth) = MONTH(NOW()) + 1;
``` ```
+588
View File
@@ -0,0 +1,588 @@
### C语言-1
```c
/*
-------------------------------------------------------
【程序填空】
---------------------------------------------------------
打印以下图案:
*****
*****
*****
*****
*****
*/
#include<stdio.h>
void main()
{
int i =0 , j =0 , k=0;
/**********Program**********/
for(i=0;i<5;i++){
for(j=0;j<i;j++){
printf(" ");
}
for(k=0;k<5;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
printf("\n");
}
```
### C语言-2
```c
/*-------------------------------------------------------
功能:编写程序,求两个非零整数之和。
-------------------------------------------------------*/
#include"stdio.h"
main()
{
int x,y,z=0;
scanf ("%d%d", &x,&y);
/**********Program**********/
if(x!=0 && y!=0){
z = x+y;
/********** End **********/
printf("z=%d\n", z);
}
else
printf("两个数中至少有一个数为零值\n");
}
```
### C语言-3
```c
/*------------------------------------------------------------------------
【程序设计】请编写函数sum,其功能是:用While循环语句求1到n之间(包括n)能
被3整除的所有整数之和,并将结果返回给主函数。(n值由主函数传入)
运行程序后若输入:10,则输出为:18
----------------------------------------------------------------------*/
#include "stdio.h"
long sum(int n)
{
/**********Program**********/
int i, s=0;
for(i=1;i<=n;i++){
if(i%3==0){
s+=i;
}
}
return s;
/********** End **********/
}
void main()
{
int x;
long f;
scanf("%d",&x);
f=sum(x);
printf("%ld\n",f);
}
```
### C语言-4
```c
/*-------------------------------------------------------
功能:设计程序打印出如下图案(菱形)
*
***
*****
*******
*****
***
*
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j,k;
/**********Program**********/
for(i=-3;i<=3;i++){
for(j=0;j<(i<0?-i:i);j++){
printf(" ");
}
for(k=0;k<7-j*2;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
}
```
### C语言-5
```c
/*------------------------------------------------------
题目:从键盘输入一个整数n,求2 至 n-1内所有能被n整除的数。
例如:输入10 输出 2 5
输入99 输出 3 9 11 33
--------------------------------------------------------*/
#include "stdio.h"
int main ( )
{
int n,i;
printf("input a number:");
scanf ("%d", &n);
/**********Program**********/
for(i=2;i<n;i++)
if(n%i==0)
/********** End **********/
printf ("%d\n",i);
}
```
### C语言-6
```c
/*-------------------------------------------------------
【程序填空】 2、有一箱苹果(100—200之间),如果分成4个苹果一组的若干组,则多2个苹果;若分成7个苹果一组,则多3个苹果; 若分成9个苹果一组,则多5个苹果,编程实现求苹果的个数。
--------------------------------------------------------*/
# include <stdio.h>
main ()
{
int i;
for(i=100;i<200;i++)
/**********Program**********/
if(i%4==2 && i%7==3 && i%9==5)
/********** End **********/
printf ("%d",i);
}
```
### C语言-7
```c
/*-------------------------------------------------------
【程序填空】---------------------------------------------------------
功能:计算武汉城区出租车收费的程序,当里程在3公里以内含3公里时收费12元,超过3公里(在0和1之间均计1公里)的部分每公里收费2元。
备注:使用switch来实现
--------------------------------------------------------*/
#include<stdio.h>
main(){
int m,n;
scanf("%d",&m);
/**********Program**********/
n=0;
switch(m){
default: n+=(m-3)*2;
case 1:
case 2:
case 3:n+=12;
}
/********** End **********/
printf("本次收费为:%d",n);
}
```
### C语言-8
```c
/*-------------------------------------------------------
功能:从键盘输入2个整数相加,再输入答案,如果正确,显示"right",否则显示"error"。
--------------------------------------------------------*/
#include "stdio.h"
main( )
{
int a,b,c;
printf("please input a and b:\n");
scanf("%d,%d",&a , &b);
printf("please input the answer:\n");
scanf("%d",&c);
/**********Program**********/
if(a+b==c)
/********** End **********/
printf("right\n");
else
printf("error\n");
}
```
### C语言-9
```c
/*-------------------------------------------------------
功能:功能:输入三角形的三边长,判断能否构成三角形,若能,利用海伦公式计
算该三角形的面积,计算结果保留3位小数。
l=(a+b+c)/2s=sqrt(l*(l-a)*(l-b)*(l-c))
--------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
float a,b,c,s,l;
scanf("%f,%f,%f",&a , &b , &c);
if(a+b<c||a+c<b||b+c<a)
printf("该3个数据不能构成三角形\n");
else
{
/**********Program**********/
l=(a+b+c)/2;
s=sqrt(l*(l-a)*(l-b)*(l-c));
/********** End **********/
printf("该三角形的面积为%.3f\n",s);
}
}
```
### C语言-10
```c
/*------------------------------------------------------------------------
【程序设计】功能:使用for循环输出Fibonacci数列的前15项,要求每行输出5项。
Fibonacci数列:1,1,2,3,5,8,13...........
----------------------------------------------------------------------*/
#include <stdio.h>
main()
{
int fib[15],i;
fib[0]=1;fib[1]=1;
/**********Program**********/
for(i=2;i<15;i++){
fib[i]=fib[i-1]+fib[i-2];
}
/********** End **********/
for(i=0;i<15;i++)
{
printf("%d\t",fib[i] );
if ( i%5==4 ) printf("\n");
}
}
```
### C语言-11
```c
/*-------------------------------------------------------
1. 判断101-200之间有多少个素数,并输出所有素数。判断素数的方法IsPrime:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。 --------------------------------------------------------*/
#include <stdio.h>
#include<math.h>
int IsPrime (int n)
{
int i=2;
for(i=2;i<=sqrt(n);i++)
/**********Program**********/
if(n%i==0){
return 0;
}
/********** End **********/
return 1;
}
int main( )
{
int i ;
for(i=100;i<=200;i++ )
{
if ( IsPrime( i) )
{
printf("% d",i);
}
}
return 0;
}
```
### C语言-12
```c
/*-------------------------------------------------------
功能:输出100到1000之间的各位数字之和能被15整除的所有数,输出时每10个一行。
输出:(每个数占5个字符)
159 168 177 186 195 249 258 267 276 285
294 339 348 357 366 375 384 393 429 438
447 456 465 474 483 492 519 528 537 546
555 564 573 582 591 609 618 627 636 645
654 663 672 681 690 708 717 726 735 744
753 762 771 780 807 816 825 834 843 852
861 870 906 915 924 933 942 951 960
-------------------------------------------------------*/
#include<stdio.h>
main()
{
int m,n,k,i=0;
for(m=100;m<=1000;m++)
{
k=0;
n=m;
/**********Program**********/
while(n){
k+=n%10;
n/=10;
}
if(k%15==0){
i++;
printf("%5d", m);
if(i%10==0){
printf("\n");
}
}
/********** End **********/
}
}
```
### C语言-13
```c
/*-------------------------------------------------------
题目: 打印以下图案:
*********
*******
*****
***
*
--------------------------------------------------------*/
#include<stdio.h>
void main()
{
int i,j,k;
for( i=0 ; i<5; i++ )
{
printf("\n");
/**********Program**********/
for(j=0;j<i*2;j++){
printf(" ");
}
for(k=0;k<9-j;k++){
printf("*");
}
/********** End **********/
}
printf("\n");
}
```
### C语言-14
```c
/*-------------------------------------------------------
1. 编写程序,打印以下图案:
*****
***
*
--------------------------------------------------------*/
#include<stdio.h>
void main()
{
int i,j,k;
/**********Program**********/
for(i=0;i<3;i++){
for(j=0;j<i;j++){
printf(" ");
}
for(k=0;k<5-j*2;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
printf("\n");
}
```
### C语言-15
```c
/*-------------------------------------------------------
功能:不用第三个变量,实现两个数的对调操作。
--------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b;
scanf("%d%d",&a , &b );
printf("a=%d,b=%d\n",a,b);
/**********Program**********/
a = a+b;
b = a-b;
a = a-b;
/********** End **********/
printf("a=%d,b=%d\n", a,b);
}
```
### C语言-16
```c
/*-------------------------------------------------------
题目:请将123-321之间偶数累加输出最终结果。
--------------------------------------------------------*/
#include <stdio.h>
int main()
{
int i;
long sum = 0;
for(i = 123; i <= 321; i++ )
{
/**********Program**********/
if(i%2==0){
sum += i;
}
/********** End **********/
}
printf ("总和为 : %ld.\n",sum);
return 0;
}
```
### C语言-17
```c
/*-------------------------------------------------------
题目:把123~321之间的可以被7整除的数输出。(使用for循环)
--------------------------------------------------------*/
#include <stdio.h>
void main()
{
int a=0;
/**********Program**********/
for(a=123;a<=321;a++){
if(a%7==0){
/********** End **********/
printf("%d\n",a);
}
}
}
```
### C语言-18
```c
/*-------------------------------------------------------
功能:依次输入十个整数,找出其平方最大的一个数并打印出来。
--------------------------------------------------------*/
#include <stdio.h>
void main()
{
int i;
float x,y,z=0;
printf("\n请输入10个数:");
for(i=1;i<=10;i++)
{
/**********Program**********/
scanf("%f", &x);
if(x*x > z){
z = x*x;
y = x;
}
/********** End **********/
}
printf("平方最大的一个数是:%f\n",y);
}
```
### C语言-19
```c
/*-------------------------------------------------------
功能:从键盘输入一位整数i,计算其各位数字之和。比如输入整数
31421,则打印结果为11。(使用while循环)
--------------------------------------------------------*/
#include<stdio.h>
main()
{
int i,sum=0,a;
scanf("%d",&i);
/**********Program**********/
while(i){
sum += i%10;
i/=10;
}
/********** End **********/
printf("%d\n",sum);
}
```
### C语言-20
```c
/*-------------------------------------------------------
功能:编写程序(使用Switch ),给出年月日,计算出该日是该年的第几天。判断是否为
闰年的条件是:能被 4 整除但是不能被100整除或者能被四百整除。
--------------------------------------------------------*/
#include"stdio.h"
main()
{
int year,month,day,days=0,i,d;
printf("请输入年-月-日:");
scanf("%d-%d-%d",&year,&month,&day);
for(i=1;i<month;i++)
{
/**********Program**********/
switch(i){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10: days+=31;break;
case 2: days+=(28 + (year%4==0&&year%100!=0 || year%400==0?1:0));break;
default: days+=30;
}
/********** End **********/
}
printf("%d-%d-%d是该年第%d天\n",year,month,day,days + day);
}
```
+549
View File
@@ -0,0 +1,549 @@
### C语言-1
```c
/*-------------------------------------------------------
编程计算:s=1×2×3×……×n (n由键盘输入,使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,n,p;
p=1;
printf("请输入一个正整数n:");
scanf("%d",&n);
/**********Program**********/
for(i=2;i<=n;i++){
p*=i;
}
/********** End **********/
printf("1*2*...*%d = %d\n",n,p);
}
```
### C语言-2
```c
/*-------------------------------------------------------
编程计算π的近似值(直到最后一项的绝对值小于10-5为止),要求保留小数点后10位: (使用while)
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,f;
double t,s;
f=1;
s=0;
i=1;
t=1.0;
/**********Program**********/
while(fabs(t/i)>1e-5){
s+=t/i*f;//计算该项的值
f*=-1;//翻转符号
i+=2;
}
/********** End **********/
s=s*4;
printf("圆周率的近似值为:%.10f\n",s);
}
```
### C语言-3
```c
/*-------------------------------------------------------
编程计算π的近似值(直到最后一项的绝对值小于10-5为止,使用while):
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
#define N 1e-5
main()
{
int i,f;
double t,s;
f=1;
s=0;
i=1;
t=1.0;
/**********Program**********/
while(fabs(t/i)>N){
s+=t/i*f;//计算该项的值
f*=-1;//翻转符号
i+=2;
}
/********** End **********/
s=s*4 ;
printf("圆周率的近似值为:%f\n",s);
}
```
### C语言-4
```c
/*-------------------------------------------------------
功能:编程实现求1-10(包含1,不包含10)之间的所有数的乘积并输出。(使用while)
--------------------------------------------------------*/
#include <stdio.h>
main( )
{
int i=1, sum=1;
/**********Program**********/
while(i<10){
sum*=i;
i++;
}
/********** End **********/
printf("the sum of odd is :%d\n",sum);
}
```
### C语言-5
```c
/*-------------------------------------------------------
功能:从键盘上输入若干个学生的成绩,统计并输出最高成绩和最
低成绩,当输入负数时结束输入。(使用while循环)
--------------------------------------------------------*/
#include <stdio.h>
main()
{
int x,max,min;
printf("please input x:\n");
scanf("%d",&x);
max=x;
min=x;
/**********Program**********/
while(x > 0){
if(x > max){
max = x;
}
if(x < min){
min = x;
}
scanf("%d", &x);
}
/********** End **********/
printf("max=%d,min=%d\n",max,min);
}
```
### C语言-6
```c
/*-------------------------------------------------------
编程计算:使用for计算,s=1+2+3+……+n n由键盘输入)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,n,sum;
sum=0;
printf("请输入一个正整数n:");
scanf("%d",&n);
/**********Program**********/
for(i=1;i<=n;i++){
sum+=i;
}
/********** End **********/
printf("1+2+...+%d = %d\n",n,sum);
}
```
### C语言-7
```c
/*-------------------------------------------------------
功能:编写比较a、b两个数的大小,且把大者赋给max,小者赋给min。
--------------------------------------------------------*/
#include"stdio.h"
main()
{
int a,b,min,max;
printf("输入两个数给a,b:");
scanf("%d,%d",&a,&b);
/**********Program**********/
if (a > b) {
max = a;
min = b;
} else {
max = b;
min = a;
}
/********** End **********/
printf("min=%d,max=%d\n",min,max);
}
```
### C语言-8
```c
/*-------------------------------------------------------
功能:输入三个整数x,y,z,请把这三个数由小到大输出。
--------------------------------------------------------*/
#include <stdio.h>
main()
{
int x,y,z,t;
scanf("%d%d%d",&x , &y , &z);
/**********Program**********/
if (x > y) {
t = x;
x = y;
y = t;
}
if (y > z) {
t = y;
y = z;
z = t;
}
if (x > y) {
t = x;
x = y;
y = t;
}
/********** End **********/
printf("small to big: %d %d %d\n",x,y,z);
}
```
### C语言-9
```c
/*-------------------------------------------------------
功能:从键盘输入整数n,输出n以内所有奇数的和。(使用for循环)
--------------------------------------------------------*/
#include<stdio.h>
void main()
{
int n,i,s;
s=0;
scanf("%d",&n);
/**********Program**********/
for(i=1;i<=n;i++){
if(i%2==1){
s+=i;
}
}
/********** End **********/
printf("s=%d\n",s);
}
```
### C语言-10
```c
/*-------------------------------------------------------
编程计算:s=1!+3!+5!+…n! n由键盘输入,使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j,n;
long p,sum;
sum=0;
printf("请输入一个正整数n:");
scanf("%d",&n);
/**********Program**********/
p = 1;
for ( i = 1;i <= n; i++ ) {
p *= i;
if ( i%2 == 1 ) {
sum += p;
}
}
/********** End **********/
printf("1!+3!+...+%d!= %d\n",n,sum);
}
```
### C语言-11
```c
/*-------------------------------------------------------
编程计算求e近似值:
用while语句求直到最后一项值小于10-5为止。
e=0+1+1/1+1/1/2+1/1/2/3...
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i;
double t,e;
i=1;
t=1.0;
e=0;
/**********Program**********/
e = 2;
i = 2;
while(t/i > 1e-5){
e += t/i;
t /= i++;
}
/********** End **********/
printf("e=%f\n",e);
}
```
### C语言-12
```c
/*-------------------------------------------------------
编程计算求e近似值: 用for语句求前50项之和。
e=0+1+1/1+1/1/2+1/1/2/3...
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i;
double t,e;
t=1.0;
e=0;
for(i=1;i<=50;i++)
{
/**********Program**********/
e += t;
t /= i;
/********** End **********/
}
printf("前50项之和为:%f\n",e);
}
```
### C语言-13
```c
/*-------------------------------------------------------
功能:输入一个圆半径(r),当r>=0时,计算并输出圆的面积(area)和周长(circumference),否则,输出提示信息。
--------------------------------------------------------*/
#include <stdio.h>
#define PI 3.14
main()
{
float r,s,l;
printf("please input r:\n");
scanf("%f",&r);
if (r>=0)
{
/**********Program**********/
s = PI * r*r;
l = 2*PI*r;
/********** End **********/
printf("the area is %f\n",s);
printf("the circumference is %f\n",l);
}
else
printf("input error!\n");
}
```
### C语言-14
```c
/*-------------------------------------------------------
功能:编写程序输入三位数(100-999),然后按数字逆序输出。(例:输入456↙,输出654)。
--------------------------------------------------------*/
#include <stdio.h>
void main()
{
int n,ge,shi,bai;
printf("请输入一个三位正整数:");
scanf("%d",&n);
if((n<100)||(n>999))
printf("输入数据有误!\n");
else
{
/**********Program**********/
ge = n % 10;
shi = n % 100 / 10;
bai = n / 100;
/********** End **********/
printf("此数的逆序输出结果为:%d%d%d\n",ge,shi,bai);
}
}
```
### C语言-15
```c
/*-------------------------------------------------------
编程计算:s=1!+2!+3!+…n! n由键盘输入,使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j,n;
long p,sum;
sum=0;
printf("请输入一个正整数n:");
scanf("%d",&n);
/**********Program**********/
p = 1;
for( i = 1;i <= n; i++ ){
p *= i;
sum += p;
}
/********** End **********/
printf("1!+2!+...+%d!= %d\n",n,sum);
}
```
### C语言-16
```c
/*-------------------------------------------------------
编程计算:s=1-3+5-7+……-99(使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,f,sum;
f=1;
sum=0;
/**********Program**********/
for(i=1;i<=99;i++){
if(i%2==1){
sum += i*f;
f*=-1;
}
}
/********** End **********/
printf("1-3+5-7+...-99 = %d\n",sum);
}
```
### C语言-17
```c
/*-------------------------------------------------------
功能:编写一个简单计算器程序,输入格式为:a op b。其中 a和b是
参加运算的两个数,op 为运算符,它的取值只能是+、-、*、/。
例:(注意输出格式)
输入:3+4
输出:3.000000+4.000000=7.000000
--------------------------------------------------------*/
#include<stdio.h>
main()
{
float a,b;
char op;
printf("Please enter a,b and op:");
scanf("%f,%c,%f",&a,&op,&b);
switch(op)
{
/**********Program**********/
case '+':printf("%f+%f=%f\n", a, b, a+b);break;
case '-':printf("%f-%f=%f\n", a, b, a-b);break;
case '*':printf("%f*%f=%f\n", a, b, a*b);break;
/********** End **********/
case '/':if(b!=0)
printf("%f/%f=%f\n",a,b,a/b);
else
printf("error!\n");break;
default:printf("error!\n");break;
}
}
```
### C语言-18
```c
/*-------------------------------------------------------
功能:编写程序,把三个整数中最大的打印出来。
--------------------------------------------------------*/
#include"stdio.h"
main()
{
int a,b,c,m;
scanf("%d,%d,%d", &a,&b,&c);
/**********Program**********/
m = a;
if( b > m ){
m = b;
}
if ( c > m ) {
m = c;
}
/********** End **********/
printf ("m=%d\n",m);
}
```
### C语言-19
```c
/*-------------------------------------------------------
功能::使用for循环打印出如下图案(菱形)
*
***
*****
*******
*****
***
*
--------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j,k;
/**********Program**********/
for(i=-3;i<=3;i++){
for(j=0;j<(i<0?-i:i);j++){
printf(" ");
}
for(k=0;k<7-j*2;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
}
```
### C语言-20
```c
/*-------------------------------------------------------
功能:找出n个数中最大的数和最小的数,并将它们的值输出出来。
--------------------------------------------------------*/
#include<stdio.h>
int main()
{
int a,n,i,min,max;
scanf("%d",&n);
scanf("%d",&a);
min=a;
max=a;
for(i=1;i<n;i++)
{
/**********Program**********/
scanf("%d", &a);
if(a > max){
max = a;
}
if(a < min){
min = a;
}
/********** End **********/
}
printf("The maximum number is %d.\n",max);
printf("The minimum number is %d.\n",min);
}
```
+657
View File
@@ -0,0 +1,657 @@
### C语言-1
```c
/*-------------------------------------------------------
任意输入一个日期,计算这一天是这一年中的第几天(考虑闰年和平年)。
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int y,m,d,s,f;
s=0;
printf("请输入一个日期(YYYY-MM-DD):");
scanf("%d-%d-%d",&y,&m,&d);
if(y%4==0&&y%100!=0||y%400==0)
f=1;
else
f=0;
switch(m-1)
{
/**********Program**********/
case 11: s+=30;
case 10: s+=31;
case 9: s+=30;
case 8: s+=31;
case 7: s+=31;
case 6: s+=30;
case 5: s+=31;
case 4: s+=30;
case 3: s+=31;
case 2: s+=f+28;
case 1: s+=31;
/********** End **********/
}
s=s+d ;
printf("%d-%d-%d是这一年中的第%d天\n",y,m,d,s);
}
```
### C语言-2
```c
/*-------------------------------------------------------
编程求s=a+aa+aaa+aaaa+aa…a的值。其中a为一个数字,例:3+33+333+3333+33333,要求a以及所加数字个数n由键盘输入,示例中a=3,n=5。(注:使用for
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,n,s,i,t;
s=t=0;
printf("请输入数字a:");
scanf("%d",&a);
printf("请输入求和的项数n:");
scanf("%d",&n);
/**********Program**********/
t = a;
for(i=0;i<n;i++){
s += t;
t*=10;
t+=a;
}
/********** End **********/
printf("s=%d\n",s);
}
```
### C语言-3
```c
/*-------------------------------------------------------
从键盘输入一个十进制整数,将其转换为二进制后反序再转成新的十进制后输出。(例:11→1011→1101→13)(注:使用while循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int n,s,t;
s=0;
printf("请输入一个整数:");
scanf("%d",&n);
/**********Program**********/
//1011 从最末尾开始 依次除出
//加入s之前将前加入的数*1
while(n){
s += s + n%2;
n /= 2;
}
/********** End **********/
printf("%d\n",s);
}
```
### C语言-4
```c
/*-------------------------------------------------------
编程判断m是否素数,m由键盘输入。(使用for)
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int m,i,k;
printf("请输入一个正整数 :");
scanf("%d",&m);
k=sqrt(m);
/**********Program**********/
for(i=2;i<=k;i++){
if(m % i == 0){
break;
}
}
/********** End **********/
if(i>k)
printf("%d是素数\n",m);
else
printf("%d不是素数\n",m);
}
```
### C语言-5
```c
/*-------------------------------------------------------
编程判断m是否素数,m由键盘输入。(使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int m,i;
printf("请输入一个正整数 :");
scanf("%d",&m);
/**********Program**********/
for(i=2;i<m;i++){
if(m%i==0){
break;
}
}
/********** End **********/
if(i==m)
printf("%d是素数\n",m);
else
printf("%d不是素数\n",m);
}
```
### C语言-6
```c
/*-------------------------------------------------------
使用for循环输出99乘法表,要求格式如图所示: (注:乘积占四个字符)
1x1=1
2x1=2 2x2=4
3x1=3 3x2=6 3x3=9
4x1=4 4x2=8 4x3=12 4x4=16
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
/**********Program**********/
for(i=1;i<10;i++){
for(j=1;j<=i;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}
```
### C语言-7
```c
/*-------------------------------------------------------
从键盘输入5个整数,输出其最大值、最小值、平均值。(注:使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int n,s,max,min,i;
double avg;
scanf("%d",&n);
s=max=min=n;
for(i=2;i<=5;i++)
{
scanf("%d",&n);
/**********Program**********/
if(n > max){
max = n;
}
if(n < min){
min = n;
}
s+=n;
/********** End **********/
}
avg=s/5.0;
printf("max=%d,min=%d,avg=%f\n",max,min,avg);
}
```
### C语言-8
```c
/*-------------------------------------------------------
编写程序,输出从公元2000年至3000年所有闰年的年号,每输出10个年号换一行。
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int year,count;
count=0;
for(year=2000;year<=3000;year++)
{
if(year%4==0&&year%100!=0 || year%400==0) {
printf("%-6d",year);
/**********Program**********/
count++;
if(count%10==0){
printf("\n");
}
}
/********** End **********/
}
}
```
### C语言-9
```c
/*-------------------------------------------------------
输入一个年月日,要求输出这一天是该年的第几天。(例如:2000年3月2日是该年的第62天)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i, year,month,day,days;
days=0;
printf("请输入一年日期(格式为:yyyy-mm-dd):");
scanf("%d-%d-%d",&year,&month,&day);
for(i=1;i<month;i++)
{
switch(i)
{
/**********Program**********/
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:days+=31;break;
case 2: days+=28;days += (year%4==0&&year%100!=0||year%400==0)?1:0;break;
default:
days+=30;
/********** End **********/ }
}
days=days+day;
printf("%d-%d-%d是这一年中的第%d天\n",year,month,day,days);
}
```
### C语言-10
```c
/*-------------------------------------------------------
求前100个素数,输出时每个数占5个字符宽度,10个一行,并输出其平均值。
结果:
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223 227 229
233 239 241 251 257 263 269 271 277 281
283 293 307 311 313 317 331 337 347 349
353 359 367 373 379 383 389 397 401 409
419 421 431 433 439 443 449 457 461 463
467 479 487 491 499 503 509 521 523 541
average=241.330000
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j,k,m,sum;
double avg;
k=0;
sum=0;
for(i=2;k<100;i++)
{
m=sqrt(i);
/**********Program**********/
for(j=2;j<=m;j++){
if(i%j==0){
break;
}
}
if(j>m){
printf("%5d", i);
k++;
sum+=i;
if(k%10==0){
printf("\n");
}
}
/********** End **********/
}
avg=sum/100.0;
printf("\naverage=%f\n",avg);
}
```
### C语言-11
```c
/*-------------------------------------------------------
求100到200间的所有素数,输出时每个数占5个字符宽度,10个一行。要求在奇数中找素数。
结果:
101 103 107 109 113 127 131 137 139 149
151 157 163 167 173 179 181 191 193 197
199
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j,k,m;
k=0;
for(i=101;i<200;i+=2 )
{
m=sqrt(i);
/**********Program**********/
for(j=2;j<=m;j++){
if(i%j==0){
break;
}
}
if(j > m){
printf("%5d", i);
k++;
if(k%10==0){
printf("\n");
}
}
/********** End **********/
}
}
```
### C语言-12
```c
/*-------------------------------------------------------
使用for循环输出99乘法表,要求格式如图所示: (注:乘积占四个字符)
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9
2x1=2 2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18
3x1=3 3x2=6 3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27
4x1=4 4x2=8 4x3=12 4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25 5x6=30 5x7=35 5x8=40 5x9=45
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36 6x7=42 6x8=48 6x9=54
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 7x8=56 7x9=63
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 8x9=72
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
/**********Program**********/
for(i=1;i<10;i++){
for(j=1;j<10;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}
```
### C语言-13
```c
/*-------------------------------------------------------
编写程序打印一个n行的菱形,n由键盘输入
输入:5
输出:
*
***
*****
***
*
-----------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j,k,n;
printf("请输入一个奇数(行数)n:");
scanf("%d",&n);
for(i=-n/2; i<=n/2;i++)
{
/**********Program**********/
for(j=0;j<abs(i);j++){
printf(" ");
}
for(k=0;k<n-j*2;k++){
printf("*");
}
printf("\n");
/********** End **********/
}
}
```
### C语言-14
```c
/*-------------------------------------------------------
编程输出500以内的“水仙花数”。“水仙花数”是一个三位数,其各位数字立方和等于该数本身(例:153=13+53+33)。(使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b,c,i;
/**********Program**********/
for(i=100;i<500;i++){
a = i%10;
b = i%100/10;
c = i/100;
if(a*a*a + b*b*b + c*c*c == i)
/********** End **********/
printf("%d\n",i);
}
}
```
### C语言-15
```c
/*-------------------------------------------------------
斐波那契数列的前几项是:1、1、2、3、5、8、13、21……编程输出该数列,直到某项的值大于10000为止,每行输出4个。
结果:
1 1 2 3
5 8 13 21
34 55 89 144
233 377 610 987
1597 2584 4181 6765
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b,c,i;
a=b=1;
printf("%d\t%d\t",a,b);
for(i=3;;i++)
{
c=a+b;
if(c>10000)
break;
printf("%d\t",c);
/**********Program**********/
if(i%4==0){
printf("\n");
}
a = b;
b = c;
}
/********** End **********/
}
```
### C语言-16
```c
/*-------------------------------------------------------
斐波那契数列的前几项是:1、1、2、3、5、8、13、21……编程输出该数列的前20项,每行输出4个。
结果:
1 1 2 3
5 8 13 21
34 55 89 144
233 377 610 987
1597 2584 4181 6765
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b,c,i;
a=b=1;
printf("%d\t%d\t",a,b);
for(i=3;i<=20;i++)
{
c=a+b;
printf("%d\t",c);
/**********Program**********/
if(i%4==0){
printf("\n");
}
a = b;
b = c;
/********** End **********/
}
}
```
### C语言-17
```c
/*-------------------------------------------------------
使用for循环输出99乘法表,要求格式如图所示:(注:格式 %dx%d=%-4d)
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9
2x1=2 2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16
3x1=3 3x2=6 3x3=9 3x4=12 3x5=15 3x6=18 3x7=21
4x1=4 4x2=8 4x3=12 4x4=16 4x5=20 4x6=24
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24
7x1=7 7x2=14 7x3=21
8x1=8 8x2=16
9x1=9
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
/**********Program**********/
for(i = 1;i<10;i++){
for(j=1;j<=10-i;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}
```
### C语言-18
```c
/*-------------------------------------------------------
使用for循环输出99乘法表,要求格式如图所示:
1x9=9
2x8=16 2x9=18
3x7=21 3x8=24 3x9=27
4x6=24 4x7=28 4x8=32 4x9=36
5x5=25 5x6=30 5x7=35 5x8=40 5x9=45
6x4=24 6x5=30 6x6=36 6x7=42 6x8=48 6x9=54
7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 7x8=56 7x9=63
8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 8x9=72
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
for(i=1;i<=9;i++)
{
for(j=1;j<10-i;j++)
{
printf("\t");
}
/**********Program**********/
for(j=10-i;j<10;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}
```
### C语言-19
```c
/*-------------------------------------------------------
使用for循环输出99乘法表,要求格式如图所示:
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9
2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18
3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27
4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36
5x5=25 5x6=30 5x7=35 5x8=40 5x9=45
6x6=36 6x7=42 6x8=48 6x9=54
7x7=49 7x8=56 7x9=63
8x8=64 8x9=72
9x9=81
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
for(i=1;i<=9;i++)
{
for(j=1;j<i;j++)
{
printf("\t");
}
/**********Program**********/
for(j=i;j<10;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}
```
### C语言-20
```c
/*-------------------------------------------------------
请编写输出以下图案的程序。(注意:需要使用math库abs)
1
123
12345
1234567
12345
123
1
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j;
for(i=-3;i<=3;i++)
{
/**********Program**********/
for(j=0;j<7-abs(i)*2;j++){
printf("%d", j+1);
}
printf("\n");
/********** End **********/
}
}
```
+579
View File
@@ -0,0 +1,579 @@
### C语言-1
```c
/*-------------------------------------------------------
输入三角形三边长,判断能否构成三角形,如能构成则输出其面积,不能则给出错误提示。
(海伦公式):
一个三角形,边长分别为a、b、c,面积S可由一下公式求得
S=√p(p-a)(p-b)(p-c)
公式里p为半周长(周长的一半):P=(a+b+c)/2
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
/**********Program**********/
double S(int a, int b, int c){
return (a+b+c)/2;
}
double AREA(double t, int a, int b, int c){
return sqrt(t*(t-a)*(t-b)*(t-c));
}
/********** End **********/
main()
{
int a,b,c;
double t,area;
printf("请输入三个正整数,表示三角形的三个边长:");
scanf("%d%d%d",&a,&b,&c);
if(a+b>c&&a+c>b&&b+c>a)
{
t=S(a,b,c);
area=AREA(t,a,b,c);
printf("三角形的面积是:%f\n",area);
}
else
printf("不能构成三角形\n");
}
```
### C语言-2
```c
/*-------------------------------------------------------
将一张100元钞票换成等值的10元,5元,2元和1元的小钞,每次换成40张小钞,要求每一种小钞都要有,编程求出所有可能的换法总数输出并输出各换法的组合。(注:使用for循环)
结果:
10元钞票有1张,5元钞票有5张,2元钞票有31张,1元钞票有3张
10元钞票有1张,5元钞票有6张,2元钞票有27张,1元钞票有6张
10元钞票有1张,5元钞票有7张,2元钞票有23张,1元钞票有9张
总共有34种换法
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b,c,d,s;
s=0;
/**********Program**********/
for(a=1;a<10;a++){
for(b=1;b<20;b++){
for(c=1;c<50;c++){
for(d=1;d<100;d++){
if(a*10+b*5+c*2+d == 100 && a+b+c+d==40){
s++;
/********** End **********/
printf("10元钞票有%d张,5元钞票有%d张,2元钞票有%d张,1元钞票有%d张\n",a,b,c,d);
}
}
}
}
}
printf("\n总共有%d种换法\n",s);
}
```
### C语言-3
```c
/*-------------------------------------------------------
编程将一个正整数分解成质因数(注:使用while循环)
例如:
输入 90
输出 90=2*3*3*5
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int n,i;
printf("请输入一个正整数:");
scanf("%d",&n);
printf("%d=",n);
i=2;
/**********Program**********/
while(n > i){
if(n%i==0){
printf("%d*", i);
n/=i;
}else{
i++;
}
}
/********** End **********/
printf("%d\n",n);
}
```
### C语言-4
```c
/*-------------------------------------------------------
韩信点兵,韩信带1500名士兵打仗,战死四五百人,站3人一排,多出2人;站5人一排,多出4人;站7人一排,多出6人。编程计算还有多少士兵? (注:使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i;
/**********Program**********/
for(i=1000;i<1100;i++){
if(i%3==2 && i%5==4 && i%7==6)
/********** End **********/
printf("还有%d名士兵\n",i);
}
}
```
### C语言-5
```c
/*-------------------------------------------------------
百马百担,有一百匹马,驮一百担货,大马驮3担,中马驮2担,两只小马驮1担,每匹马都要驮货,编程计算大马(dm)、中马(zm)、小马(xm)各有多少匹。 (注:使用for循环)
结果:
大马有2匹,中马有30匹,小马有68匹
大马有5匹,中马有25匹,小马有70匹
大马有8匹,中马有20匹,小马有72匹
大马有11匹,中马有15匹,小马有74匹
大马有14匹,中马有10匹,小马有76匹
大马有17匹,中马有5匹,小马有78匹
-------------------------------------------------------*/
#include <stdio.h>
void main() {
int dm,zm,xm;
/**********Program**********/
for(dm=1;dm<66;dm++){
for(zm=1;zm<100;zm++){
for(xm=2;xm<200;xm+=2){
if(dm*3+zm*2+xm/2 == 100 && dm+zm+xm==100)
/********** End **********/
printf("大马有%d匹,中马有%d匹,小马有%d匹\n",dm,zm,xm);
}
}
}
}
```
### C语言-6
```c
/*-------------------------------------------------------
鸡兔同笼,《孙子算经》中记载:“今有雉兔同笼,上有三十五头,下有九十四足,问雉兔各几何?”,编程计算鸡和兔子各有多少只。(注:使用for循环)
结果:
鸡有23只,兔有12只
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int j,t;
/**********Program**********/
for(j=1;j<35;j++){
for(t=1;t<35;t++){
if(j*2+t*4==94 && j+t == 35)
/********** End **********/
printf("鸡有%d只,兔有%d只\n",j,t);
}
}
}
```
### C语言-7
```c
/*-------------------------------------------------------
编程输出1000以内的完数,所谓完数是指一个数的所有因子(包含1但不包含其本身)之和等于这个数本身。(例:28=1+2+4+7+14
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j,s;
for(i=2;i<=1000;i++)
{
s=0;
/**********Program**********/
for(j=1;j<i;j++){
if(i%j==0){
s+=j;
}
}
/********** End **********/
if(s==i)
printf("%d\n",i);
}
}
```
### C语言-8
```c
/*-------------------------------------------------------
编程求所有能被3且能被5且能被7整除的三位数并输出(每个数字占5字符宽度,5个一行)。
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,k;
k=0;
for(i=100;i<=999;i++)
{
/**********Program**********/
if(i%3 ==0 && i%5==0 && i%7==0){
/********** End **********/
printf("%5d",i);
k++;
if(k%5==0)
printf("\n");
}
}
}
```
### C语言-9
```c
/*-------------------------------------------------------
输入一个整数,判断是否为回文数(所谓回文数就是左右对称的数)
(注:使用while循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int n,t,s;
s=0;
scanf("%d",&n);
t=n;
/**********Program**********/
while(n){
s*=10;
s+=n%10;
n/=10;
}
/********** End **********/
if( t==s )
printf("yes\n");
else
printf("no\n");
}
```
### C语言-10
```c
/*-------------------------------------------------------
百钱买百鸡,《算经》一书中记载
“鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一,百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?”
要求每一种鸡都要有,编程输出公鸡(gj)、母鸡(mj)、小鸡(xj)各有多少只。
结果:(注:使用for循环)
公鸡有4只,母鸡有18只,小鸡有78只
公鸡有8只,母鸡有11只,小鸡有81只
公鸡有12只,母鸡有4只,小鸡有84只
-------------------------------------------------------*/
#include <stdio.h>
void main()
{
int gj,mj,xj;
/**********Program**********/
for(gj=1;gj<20;gj++){
for(mj=1;mj<34;mj++){
for(xj=3;xj<300;xj+=3){
if(gj+mj+xj==100 && gj*5+mj*3+xj/3 == 100)
/********** End **********/
printf("公鸡有%d只,母鸡有%d只,小鸡有%d只\n",gj,mj,xj);
}
}
}
}
```
### C语言-11
```c
/*-------------------------------------------------------
《孙子算经》中有这样一道算术题:“今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二,问物几何?” (注:使用while循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i;
i=1;
/**********Program**********/
while(1){
if(i%3==2&&i%5==3&&i%7==2)
/********** End **********/
{
printf("%d\n",i);
break;
}
i++;
}
}
```
### C语言-12
```c
/*-------------------------------------------------------
61.【程序功能】猴子吃桃,猴子第一天摘下若干个桃子, 吃了总数的一半,还不过瘾,又多吃了一个。第二天又将剩下的桃子吃掉一半,又多吃了一个。以后每天都这样吃。到第十天时, 发现只有一个桃子了。编程求第一天摘了多少个桃子。(注:使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
void main() {
int i,t;
t=1;
/**********Program**********/
for(i=0;i<9;i++){
t=(t+1)*2;
}
/********** End **********/
printf("第一天共摘了%d只桃\n",t);
}
```
### C语言-13
```c
/*-------------------------------------------------------
编写函数(sum),计算1+2+3+…+n的和,n由键盘输入。
-------------------------------------------------------*/
#include <stdio.h>
int sum(int n);
main()
{
int n,s;
printf("请输入一个整数n:");
scanf("%d",&n);
s=sum(n);
printf("1+2+...+%d=%d\n",n,s);
}
/**********Program**********/
int sum(int n){
int s = 0, i;
for(i=1;i<=n;i++){
s += i;
}
return s;
}
/********** End **********/
```
### C语言-14
```c
/*-------------------------------------------------------
编程用“碾转相除法”求两个整数的最大公约数,两个整数由键盘输入。(注:使用while循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int m,n,t;
printf("请输入两个整数:");
scanf("%d%d",&m,&n);
t=m%n;
/**********Program**********/
while(t){
m = n;
n = t;
t = m%n;
}
/********** End **********/
printf("最大公约数是:%d\n",n);
}
```
### C语言-15
```c
/*-------------------------------------------------------
一个正整数加上100后是完全平方数,加上268后还是一个完全平方数,编程求出这样的数并输出(在10000以内求)。
结果:
21
261
1581
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j,k;
for(i=1;i<=10000;i++)
{
/**********Program**********/
if(pow((int)sqrt(i+100), 2) == i+100 && pow((int)sqrt(i+268), 2) == i+268){
/********** End **********/
printf("%d\n",i);
}
}
}
```
### C语言-16
```c
/*-------------------------------------------------------
输入一个整数,输出该数所有因子(1和它本身除外)之和。例如6的因子有2和3,则输出5
(注:使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int n,i,s;
printf("请输入一个整数n");
scanf("%d",&n);
s=0;
/**********Program**********/
for(i=2;i<n;i++){
if(n%i==0){
s+=i;
}
}
/********** End **********/
printf("s=%d\n",s);
}
```
### C语言-17
```c
/*-------------------------------------------------------
编程求100以内的所有奇数之和,以及偶数之和。(注:使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,odd,even;
odd=even=0;
/**********Program**********/
for(i=1;i<=100;i++){
if(i%2){
odd+=i;
}else{
even+=i;
}
}
/********** End **********/
printf("奇数之和为:%d,偶数之和为:%d\n",odd,even);
}
```
### C语言-18
```c
/*-------------------------------------------------------
输出100-1000以内所有的回文数,一行10个。(注:每个数占5个字符)
101 111 121 131 141 151 161 171 181 191
202 212 222 232 242 252 262 272 282 292
303 313 323 333 343 353 363 373 383 393
404 414 424 434 444 454 464 474 484 494
505 515 525 535 545 555 565 575 585 595
606 616 626 636 646 656 666 676 686 696
707 717 727 737 747 757 767 777 787 797
808 818 828 838 848 858 868 878 888 898
909 919 929 939 949 959 969 979 989 999
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,s,t,k;
k=0;
/**********Program**********/
for(i=100;i<1000;i++){
s = 0;
t = i;
while(t){
s*=10;
s+=t%10;
t/=10;
}
if(s == i){
printf("%5d", i);
k++;
if(k%10==0){
printf("\n");
}
}
}
/********** End **********/
}
```
### C语言-19
```c
/*-------------------------------------------------------
编程求用1,2,3,4四个数字可以组成多少个无重复数字的四位数,并输出这些四位数。(注:使用for循环)
结果:
1234
1243
1324
可以组成24个无重复数字的四位数
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b,c,d,count;
count=0;
/**********Program**********/
for(a=1;a<5;a++)
for(b=1;b<5;b++)
for(c=1;c<5;c++)
for(d=1;d<5;d++)
if(a!=b && a!=c && a!=d && b!=c && b!=d && c!=d){
printf("%d%d%d%d\n", a, b, c, d);
count++;
}
/********** End **********/
printf("可以组成%d个无重复数字的四位数\n",count);
}
```
### C语言-20
```c
/*-------------------------------------------------------
一小球从100米落下,每次弹跳原来一半高,求第10次落地时经过的距离及第10次弹跳的高度。
(注:使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i;
double h,s;
s=100;
h=50;
/**********Program**********/
for(i=0;i<9;i++){
s+=h*2;
h/=2;
}
/********** End **********/
printf("第10次落地时经过的距离为%f米,第10次弹跳的高度为%f米\n",s,h);
}
```
@@ -243,7 +243,146 @@ WHERE b.note = a.author_name
GROUP BY a.author_id GROUP BY a.author_id
HAVING COUNT(*) > 1; HAVING COUNT(*) > 1;
#9 视图
CREATE VIEW v_book AS
SELECT b.genre, a.author_name, COUNT(*) c
FROM tb_books b, tb_authors a
WHERE b.note = a.author_name
GROUP BY b.genre, a.author_id #按照图书类别和作者名称进行分组
HAVING COUNT(*) = ( #子查询用来统计这个类别中 数量最多的作者的图书数量
SELECT COUNT(*)
FROM tb_books
WHERE b.genre = genre
GROUP BY note
ORDER BY COUNT(*) DESC
LIMIT 1
);
#9 #10 触发器
DELIMITER $$
DROP TRIGGER IF EXISTS tri_updateCentury;
CREATE TRIGGER tri_updateCentury
BEFORE UPDATE ON tb_books
FOR EACH ROW
BEGIN
#方式一
/*
计算出世纪数+字符串拼接
IF NEW.publication_date <> OLD.publication_date THEN
SET NEW.century = CONCAT(FLOOR(YEAR(NEW.publication_date)/100) + 1, '世纪');
END IF;
*/
#方式二 使用多分支IF
IF NEW.publication_date <> OLD.publication_date THEN
IF YEAR(NEW.publication_date) BETWEEN 1800 AND 1899 THEN
SET NEW.century = '19世纪';
ELSEIF YEAR(NEW.publication_date) BETWEEN 1900 AND 1999 THEN
SET NEW.century = '20世纪';
ELSEIF YEAR(NEW.publication_date) BETWEEN 2000 AND 2099 THEN
SET NEW.century = '21世纪';
END IF;
END IF;
END $$
DELIMITER ;
SELECT CONCAT(FLOOR(YEAR(publication_date)/100) + 1, '世纪')
FROM tb_books;
#11 存储过程
DELIMITER $$
DROP PROCEDURE IF EXISTS pro_GetTopFictionPrice;
CREATE PROCEDURE pro_GetTopFictionPrice(IN in_genre VARCHAR(255), OUT out_title VARCHAR(255))
BEGIN
SELECT b.title INTO out_title
FROM tb_books b
WHERE b.genre = in_genre AND YEAR(b.publication_date) BETWEEN 2000 AND 2099
ORDER BY b.price DESC
LIMIT 1;
END $$
DELIMITER ;
``` ```
### 第四套
```sql
#1
ALTER TABLE tb_students MODIFY gender ENUM('男', '女', '未知');
#2
ALTER TABLE tb_scores MODIFY score FLOAT(7, 2);
#3
CREATE TABLE tb_scores_bak1 AS
SELECT *
FROM tb_scores;
#4
UPDATE test1 t1, (
SELECT tname, CONCAT(tname,'@',COUNT(*)) str
FROM test1
GROUP BY tname
HAVING COUNT(*) IN (3, 4)
)t2
SET t1.tname = t2.str
WHERE t1.tname = t2.tname;
#5
SELECT *
FROM tb_courses c
ORDER BY c.cid+0
LIMIT 4, 11;
#6
SELECT s.stuname, TIMESTAMPDIFF(YEAR,s.birthday,'2023-12-01')
FROM tb_students s
WHERE TIMESTAMPDIFF(YEAR,s.birthday,'2023-12-01') BETWEEN 30 AND 40;
#7
SELECT st.stuname, st.gender, st.birthday, c.cname, sc.score,
IF(sc.score >= 90, '优秀',
IF(sc.score >= 80, '良好',
IF(sc.score >= 70, '中等',
IF(sc.score >= 60, '及格', '不及格'))))
FROM tb_students st, tb_scores sc, tb_courses c
WHERE st.stuid = sc.student_id AND sc.course_id = c.cid
ORDER BY sc.score DESC;
#8
CREATE VIEW v_scores AS
SELECT c.cname, CEIL(AVG(sc.score)), MAX(sc.score), MIN(sc.score)
FROM tb_students st, tb_scores sc, tb_courses c
WHERE st.stuid = sc.student_id AND sc.course_id = c.cid
GROUP BY c.cid;
#9
DELIMITER $$
CREATE TRIGGER tri_updateAgeGroup
BEFORE UPDATE ON tb_students
FOR EACH ROW
BEGIN
IF YEAR(NEW.birthday) BETWEEN 2004 AND 2024 THEN
SET NEW.age_group = '青年';
ELSEIF YEAR(NEW.birthday) BETWEEN 1984 AND 2003 THEN
SET NEW.age_group = '中年';
ELSEIF YEAR(NEW.birthday) < 1984 THEN
SET NEW.age_group = '老年';
END IF;
END $$
DELIMITER ;
#10
DELIMITER $$
DROP PROCEDURE IF EXISTS pro_GetTopStudent;
CREATE PROCEDURE pro_GetTopStudent(IN in_cid CHAR(11), OUT out_stuname VARCHAR(50))
BEGIN
SELECT st.stuname INTO out_stuname
FROM tb_students st, tb_scores sc
WHERE st.stuid = sc.student_id AND sc.course_id = in_cid
ORDER BY sc.score DESC
LIMIT 1;
END $$
DELIMITER ;
CALL pro_GetTopStudent(1, @result);
SELECT @result;
```
+297
View File
@@ -0,0 +1,297 @@
### C语言-1
```c
/*------------------------------------------------------------------------------
(1)【程序设计】下列给定程序中,fun函数的功能是:分别统计字符串中大写字母和小写字母的个数。
例如,给字符串s输入:AAaaBBbb123CCcccd,则应输出:upper6lower8。
------------------------------------------------------------------------------*/
#include <stdio.h>
void fun ( char *s, int *a, int *b)
{
/**********Program**********/
while(*s != '\0'){
if(*s >= 'A' && *s <= 'Z'){
(*a)++;
}
if(*s >= 'a' && *s <= 'z'){
(*b)++;
}
s++;
}
/********** End **********/
}
main( )
{
char s[100];
int upper=0, lower=0;
printf( "\nPlease a string : " );
gets(s);
fun(s,&upper,&lower);
printf("\n upper=%d lower=%d\n",upper,lower );
}
```
### C语言-2
```c
/*------------------------------------------------------------------------
题目:函数fun的功能:将字符串str中第k个字符开始的n个字符逆序重排,
例如:输入1,5 输出54321abcde
输入3,6 输出12cba543de
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,仅在
Program-End之间填入若干语句。不要删除标志否则不得分。
----------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
void fun(char *str, int k, int n )
{
int i,j; char t;
for(i=k-1,j=k-1+n-1;i<j;i++,j--)
{
/**********Program**********/
t = str[i];
str[i] = str[j];
str[j] = t;
/********** End **********/
}
}
int main( )
{
char str[]="12345abcde";
unsigned int k,n;
scanf("%d,%d",&k,&n);
if(k+n-1<=strlen(str))
{ fun(str,k,n);
puts(str); }
else
printf("所输入的k,n值不合适!\n");
return 0;
}
```
### C语言-3
```c
/*------------------------------------------------------------------
功能:编程统计一个字符串中的字母、数字、空格和其它字符的个数。
---------------------------------------------------------------------*/
#include <stdio.h>
void fun(char s[],int b[])
{
int i;
/**********Program**********/
i=0;
while(s[i] != '\0'){
if(s[i] >= 'a' && s[i] <= 'z' || s[i] >= 'A' && s[i] <= 'Z'){
b[0]++;
}else if(s[i] >= '0' && s[i] <= '9'){
b[1]++;
}else if(s[i] == ' '){
b[2]++;
}else{
b[3]++;
}
i++;
}
/********** End **********/
}
main ()
{
char s1[80];int a[4]={0};
int k;
void fun(char s[],int b[]) ;
gets(s1);
fun(s1,a);
puts(s1);
for(k=0;k<4;k++)
printf("%4d",a[k]);
}
```
### C语言-4
```c
/*------------------------------------------------------------------------
程序功能:从键盘输入三个整数,比较三个数并显示相应信息,具体如下:
(1)如果三个数都相等,显示"***"
(2)如果三个数中只有某两个数相等,显示"@@"
(3)如果三个数互不相等,则显示"&"。
(输出要换行)
------------------------------------------------------------------------
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,仅在
Program-End之间删除【?】填入若干语句。不要删除标志否则不得分。
----------------------------------------------------------------------*/
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a==b && b==c)
printf("***\n");
/**********Program**********/
else if(a==b || b==c || a==c)
/********** End **********/
printf("@@\n");
else printf("&\n");
return 0;
}
```
### MySQL-1
```sql
#1
CREATE TABLE t_hotel_manager(
mid INT PRIMARY KEY,
hid INT NOT NULL,
mname VARCHAR(10) NOT NULL,
mage INT NOT NULL,
mgender ENUM('', '', '未知'),
telephone VARCHAR(11)
);
#2
#使MODIFY添加主键字段为自动增长
ALTER TABLE t_hotel_manager MODIFY mid INT AUTO_INCREMENT;
#
ALTER TABLE t_hotel_manager AUTO_INCREMENT = 1000;
#3
INSERT INTO t_hotel_manager()
VALUES(DEFAULT, 10001, '王璐', 32, '', NULL);
#4
CREATE TABLE t_hotel_bak AS
SELECT *
FROM t_hotel;
#5
UPDATE t_client c
SET c.integral = c.integral + 100
WHERE c.cname LIKE '姚%';
#6 tj11
SELECT c.cname, SUM(r.price)
FROM t_booking b, t_client c, t_room r
WHERE b.cid = c.cid AND b.rid = r.rid
GROUP BY c.cid
ORDER BY 2 DESC
LIMIT 9, 1;
#7 tj12
SELECT h.hname, r.price
FROM t_hotel h, t_room r
WHERE h.hid = r.hid AND r.rname = '大床房' AND r.price = (
SELECT MAX(price)
FROM t_room
WHERE rname = '大床房'
);
#8 tj13
SELECT h.hname, r.rname, r.price
FROM t_room r
LEFT JOIN t_booking b ON r.rid = b.rid
INNER JOIN t_hotel h ON r.hid = h.hid
WHERE b.bid IS NULL;
#9
CREATE VIEW v_tongji AS
SELECT h.hname, SUM(r.price)
FROM t_hotel h, t_booking b, t_room r
WHERE h.hid = r.hid AND b.rid = r.rid
GROUP BY h.hid;
```
### MySQL-2
```sql
#1
ALTER TABLE tb_student ADD PRIMARY KEY(student_id);
#2
ALTER TABLE tb_student ALTER gender SET DEFAULT '';
#3
INSERT INTO tb_student()
VALUES(10025, '张三', DEFAULT, '2012-10-01', 1001);
#4
UPDATE tb_teacher t
SET t.teacher_age = 36
WHERE t.teacher_name = '王老师';
#5 tj11
SELECT MAX(t.teacher_age)
FROM tb_teacher t;
#6 tj12
SELECT c.class_name, s.student_name, s.gender
FROM tb_teacher t, tb_student s, tb_class C
where s.class_id = c.class_id AND c.teacher_id = t.teacher_id;
#7
CREATE VIEW v_teacher AS
SELECT c.class_name, t.teacher_name, COUNT(*)
FROM tb_teacher t, tb_student s, tb_class C
WHERE s.class_id = c.class_id AND c.teacher_id = t.teacher_id
GROUP BY c.class_id, t.teacher_name;
#8
DELIMITER $$
DROP TRIGGER IF EXISTS tri_updateTeacherAge;
CREATE TRIGGER tri_updateTeacherAge
BEFORE UPDATE ON tb_teacher
FOR EACH ROW
BEGIN
IF NEW.teacher_age < 30 THEN
SET NEW.age = '青年';
ELSEIF NEW.teacher_age < 50 THEN
SET NEW.age = '中年';
ELSE
SET NEW.age = '老年';
END IF;
END $$
DELIMITER ;
#9
DELIMITER $$
DROP PROCEDURE IF EXISTS Pro_GetOldClassStudent;
CREATE PROCEDURE Pro_GetOldClassStudent(IN in_class_id INT, OUT out_student_name VARCHAR(50))
BEGIN
SELECT s.student_name INTO out_student_name
FROM tb_student s, tb_class c
WHERE s.class_id = c.class_id AND c.class_id = in_class_id
ORDER BY s.birthday
LIMIT 1;
END $$
DELIMITER ;
CALL Pro_GetOldClassStudent(1001, @result);
SELECT @result;
```
+413
View File
@@ -0,0 +1,413 @@
### C语言-1
```c
/*---------------------------------------------------------
【程序设计】程序将由数字字符组成的字符串转换为10进制实数,
例如将"123.4567"转换为123.45670。
输出如下:
123.45670
0.12345
4567.00000
------------------------------------------------------------------------
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,仅在
Program-End之间填入若干语句。不要删除标志否则不得分。
---------------------------------------------------------*/
#include<stdio.h>
#include<ctype.h>
double conver(char s[]){
int I,i,poi;
double F,p;
F=I=i=poi=0;
p=0.1;
/**********Program**********/
while(s[i] != '.'){
I*=10;
I+=s[i]-48;
i++;
}
i++;
while(s[i] != '\0'){
F+=(s[i]-48)*p;
p*=0.1;
i++;
}
/********** End **********/
return I+F;
}
int main()
{
char d[3][15]={"123.4567","0.12345","4567.0"};
int i;
for(i=0;i<3;i++)
printf("%12.5f\n",conver(d[i]));
return 0;
}
```
### C语言-2
```c
/*
-------------------------------------------------------
【程序填空】
---------------------------------------------------------
打印以下图案:
*****
*****
*****
*****
*****
*/
#include<stdio.h>
void main()
{
int i =0 , j =0 , k=0;
/**********Program**********/
for(i=0;i<5;i++){
for(j=0;j<i;j++){
printf(" ");
}
for(k=0;k<5;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
printf("\n");
}
```
### C语言-3
```c
/*-------------------------------------------------------
功能:功能:输入三角形的三边长,判断能否构成三角形,若能,利用海伦公式计
算该三角形的面积,计算结果保留3位小数。
l=(a+b+c)/2s=sqrt(l*(l-a)*(l-b)*(l-c))
--------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
float a,b,c,s,l;
scanf("%f,%f,%f",&a , &b , &c);
if(a+b<c||a+c<b||b+c<a)
printf("该3个数据不能构成三角形\n");
else
{
/**********Program**********/
l=(a+b+c)/2;
s=sqrt(l*(l-a)*(l-b)*(l-c));
/********** End **********/
printf("该三角形的面积为%.3f\n",s);
}
}
```
### C语言-4
```c
/*-------------------------------------------------------
编写程序,打印以下图形:
*
***
*****
*******
*****
***
*
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j,k;
for(i=-3;i<=3;i++)
{
/**********Program**********/
for(j=0;j<abs(i);j++){
printf(" ");
}
for(k=0;k<7-2*j;k++){
printf("*");
}
printf("\n");
/********** End **********/
}
}
```
### C语言-5
```c
/*-----------------------------------------------------------
功能:从键盘为一维整型数组输入10个整数,调用函数找出其中
最小的数并输出。
-----------------------------------------------------------*/
#include <stdio.h>
#include<stdlib.h>
/**********Program**********/
int fun(int *a, int n){
int min = a[0], i;
for(i=1;i<n;i++){
if(min > a[i]){
min = a[i];
}
}
return min;
}
/********** End **********/
main()
{
int a[10],i,min;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<10;i++)
printf("%3d",a[i]);
printf("\n");
min=fun(a,10);
printf("min=%d\n",min);
}
```
### C语言-6
```c
/*------------------------------------------------------------------------------
【程序设计】编写函数rtrim,用来删除字符串尾部的空格,首部和中间的空格不删除。例如:字符串为:" A BC DEF "
删除后的结果是" A BC DEF"。要求函数形参采用指针变量。
测试输入: A BC DEF
测试输出: A BC DEF
说明:测试输入中,A前有4个空格,F后有5个空格
------------------------------------------------------------------------
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,否则不得分。
仅在Program-End之间填入若干语句。不要删除标志否则不得分。
------------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
void main()
{
void rtrim(char *p);
char s[100];
gets(s);
rtrim(s);
puts(s);
}
void rtrim(char *p)
{
int i;
/**********Program**********/
while(*p != '\0'){
p++;
}
p--;//定位到结束符前的位置
while(*p==' '){//如果当前指针位置是空格则指针向前移
p--;
}
p++;//移动当前位置后一个空格位
*p='\0';
/********** End **********/
}
```
### C语言-7
```c
/*------------------------------------------------------------------------------
【程序设计】输入字符串(不包含空格),将字符串按字符从小到大排序,然后输出字符串中除去ASCII码值能被3整除的字符。
输入输出如下:
hello world
处理后的字符串为: dehw
------------------------------------------------------------------------
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,否则不得分。
仅在Program-End之间填入若干语句。不要删除标志否则不得分。
------------------------------------------------------------------------------*/
#include<stdio.h>
#include <string.h>
void main()
{
char str[100];
int n,i,j,t;
gets(str);
n=strlen(str);
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
if(str[j]>str[j+1])
{
t=str[j];str[j]=str[j+1];str[j+1]=t;
}
}
printf("处理后的字符串为:");
/**********Program**********/
j=0;
for(i=0;i<strlen(str);i++){
if(str[i]%3==0){
continue;
}
str[j++] = str[i];
}
str[j]='\0';
puts(str);
/********** End **********/
printf("\n");
}
```
### C语言-8
```c
/*------------------------------------------------------------------------------
【程序设计】该程序实现的功能是:求一个整数各位数字之和。(使用while实现)
------------------------------------------------------------------------
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,否则不得分。
仅在Program-End之间填入若干语句。不要删除标志否则不得分。
------------------------------------------------------------------------------*/
#include<stdio.h>
int getsum(int m)
{
int i,s=0;
/**********Program**********/
while(m){
s+=m%10;
m/=10;
}
return s;
/********** End **********/
}
int main()
{
int n,sum;
scanf("%d",&n);
sum=getsum(n);
printf("结果是%d\n",sum);
}
```
### C语言-9
```c
/*------------------------------------------------------------------------------
【程序设计】有两个降序排列的集合A和B,A中无重复元素,B中也无重复元素,
求集合B-A的差集(即:这些元素属于集合B但不属于集合A),存放于数组c中,并输出。
输入输出如下:
请输入3个整数:
3 2 1
请输入5个整数:
9 6 5 3 2
结果为:
9 6 5
------------------------------------------------------------------------
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,否则不得分。
仅在Program-End之间填入若干语句。不要删除标志否则不得分。
------------------------------------------------------------------------------*/
#include<stdio.h>
void main()
{
int a[3],b[5],c[5];
int t=0,i,j=0;
printf("请输入3个整数:\n");
for(i=0;i<3;i++){
scanf("%d",&a[i]);
}
printf("请输入5个整数:\n");
for(i=0;i<5;i++){
scanf("%d",&b[i]);
}
i=0;
/**********Program**********/
while(i<3 && j<5){
if(a[i] < b[j]){
c[t++]=b[j++];
}else if(a[i] > b[j]){
i++;
}else{
i++;
j++;
}
}
/********** End **********/
while(j<5){
c[t++]=b[j++];
}
printf("结果为:\n");
for(i=0;i<t;i++){
printf("%d ",c[i]);
}
}
```
### C语言-10
```c
/*----------------------------------------------------------------------
【程序设计】
------------------------------------------------------------------------
随机输入一字符串(不包含空格,长度不超过100),删除字符串中的数字字符后输出。
例输入:I will be 17 years old soon, and I will graduate from high school in June 2025
输出:
去掉数字后的字符串为:I will be years old soon, and I will graduate from high school in June
------------------------------------------------------------------------
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,仅在
Program-End之间填入若干语句。
不要删除标志否则不得分。
不要修改或删除Program-End之外的内容否则不得分。
----------------------------------------------------------------------*/
#include<stdio.h>
#include <string.h>
void main()
{
char a[100],b[100];
int l,i,j;
gets(a);
l=strlen(a);
j=0;
/**********Program**********/
for(i=0;i<l;i++){
if(a[i] > '9' || a[i] < '0'){
b[j++] = a[i];
}
}
/********** End **********/
b[j]='\0';
printf("去掉数字后的字符串为:");
puts(b);
}
```
@@ -0,0 +1,32 @@
/*
-------------------------------------------------------
【程序填空】
---------------------------------------------------------
打印以下图案:
*****
*****
*****
*****
*****
*/
#include<stdio.h>
void main()
{
int i =0 , j =0 , k=0;
/**********Program**********/
for(i=0;i<5;i++){
for(j=0;j<i;j++){
printf(" ");
}
for(k=0;k<5;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
printf("\n");
}
@@ -0,0 +1,25 @@
/*------------------------------------------------------------------------
【程序设计】功能:使用for循环输出Fibonacci数列的前15项,要求每行输出5项。
Fibonacci数列:1,1,2,3,5,8,13...........
----------------------------------------------------------------------*/
#include <stdio.h>
main()
{
int fib[15],i;
fib[0]=1;fib[1]=1;
/**********Program**********/
for(i=2;i<15;i++){
fib[i]=fib[i-1]+fib[i-2];
}
/********** End **********/
for(i=0;i<15;i++)
{
printf("%d\t",fib[i] );
if ( i%5==4 ) printf("\n");
}
}
@@ -0,0 +1,34 @@
/*-------------------------------------------------------
1. 判断101-200之间有多少个素数,并输出所有素数。判断素数的方法IsPrime:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。 --------------------------------------------------------*/
#include <stdio.h>
#include<math.h>
int IsPrime (int n)
{
int i=2;
for(i=2;i<=sqrt(n);i++)
/**********Program**********/
if(n%i==0){
return 0;
}
/********** End **********/
return 1;
}
int main( )
{
int i ;
for(i=100;i<=200;i++ )
{
if ( IsPrime( i) )
{
printf("% d",i);
}
}
return 0;
}
@@ -0,0 +1,40 @@
/*-------------------------------------------------------
功能:输出100到1000之间的各位数字之和能被15整除的所有数,输出时每10个一行。
输出:(每个数占5个字符)
159 168 177 186 195 249 258 267 276 285
294 339 348 357 366 375 384 393 429 438
447 456 465 474 483 492 519 528 537 546
555 564 573 582 591 609 618 627 636 645
654 663 672 681 690 708 717 726 735 744
753 762 771 780 807 816 825 834 843 852
861 870 906 915 924 933 942 951 960
-------------------------------------------------------*/
#include<stdio.h>
main()
{
int m,n,k,i=0;
for(m=100;m<=1000;m++)
{
k=0;
n=m;
/**********Program**********/
while(n){
k+=n%10;
n/=10;
}
if(k%15==0){
i++;
printf("%5d", m);
if(i%10==0){
printf("\n");
}
}
/********** End **********/
}
}
@@ -0,0 +1,31 @@
/*-------------------------------------------------------
题目: 打印以下图案:
*********
*******
*****
***
*
--------------------------------------------------------*/
#include<stdio.h>
void main()
{
int i,j,k;
for( i=0 ; i<5; i++ )
{
printf("\n");
/**********Program**********/
for(j=0;j<i*2;j++){
printf(" ");
}
for(k=0;k<9-j;k++){
printf("*");
}
/********** End **********/
}
printf("\n");
}
@@ -0,0 +1,29 @@
/*-------------------------------------------------------
1. 编写程序,打印以下图案:
*****
***
*
--------------------------------------------------------*/
#include<stdio.h>
void main()
{
int i,j,k;
/**********Program**********/
for(i=0;i<3;i++){
for(j=0;j<i;j++){
printf(" ");
}
for(k=0;k<5-j*2;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
printf("\n");
}
@@ -0,0 +1,20 @@
/*-------------------------------------------------------
功能:不用第三个变量,实现两个数的对调操作。
--------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b;
scanf("%d%d",&a , &b );
printf("a=%d,b=%d\n",a,b);
/**********Program**********/
a = a+b;
b = a-b;
a = a-b;
/********** End **********/
printf("a=%d,b=%d\n", a,b);
}
@@ -0,0 +1,20 @@
/*-------------------------------------------------------
题目:请将123-321之间偶数累加输出最终结果。
--------------------------------------------------------*/
#include <stdio.h>
int main()
{
int i;
long sum = 0;
for(i = 123; i <= 321; i++ )
{
/**********Program**********/
if(i%2==0){
sum += i;
}
/********** End **********/
}
printf ("总和为 : %ld.\n",sum);
return 0;
}
@@ -0,0 +1,19 @@
/*-------------------------------------------------------
题目:把123~321之间的可以被7整除的数输出。(使用for循环)
--------------------------------------------------------*/
#include <stdio.h>
void main()
{
int a=0;
/**********Program**********/
for(a=123;a<=321;a++){
if(a%7==0){
/********** End **********/
printf("%d\n",a);
}
}
}
@@ -0,0 +1,21 @@
/*-------------------------------------------------------
功能:依次输入十个整数,找出其平方最大的一个数并打印出来。
--------------------------------------------------------*/
#include <stdio.h>
void main()
{
int i;
float x,y,z=0;
printf("\n请输入10个数:");
for(i=1;i<=10;i++)
{
/**********Program**********/
scanf("%f", &x);
if(x*x > z){
z = x*x;
y = x;
}
/********** End **********/
}
printf("平方最大的一个数是:%f\n",y);
}
@@ -0,0 +1,21 @@
/*-------------------------------------------------------
功能:从键盘输入一位整数i,计算其各位数字之和。比如输入整数
31421,则打印结果为11。(使用while循环)
--------------------------------------------------------*/
#include<stdio.h>
main()
{
int i,sum=0,a;
scanf("%d",&i);
/**********Program**********/
while(i){
sum += i%10;
i/=10;
}
/********** End **********/
printf("%d\n",sum);
}
@@ -0,0 +1,20 @@
/*-------------------------------------------------------
功能:编写程序,求两个非零整数之和。
-------------------------------------------------------*/
#include"stdio.h"
main()
{
int x,y,z=0;
scanf ("%d%d", &x,&y);
/**********Program**********/
if(x!=0 && y!=0){
z = x+y;
/********** End **********/
printf("z=%d\n", z);
}
else
printf("两个数中至少有一个数为零值\n");
}
@@ -0,0 +1,27 @@
/*-------------------------------------------------------
功能:编写程序(使用Switch ),给出年月日,计算出该日是该年的第几天。判断是否为
闰年的条件是:能被 4 整除但是不能被100整除或者能被四百整除。
--------------------------------------------------------*/
#include"stdio.h"
main()
{
int year,month,day,days=0,i,d;
printf("请输入年-月-日:");
scanf("%d-%d-%d",&year,&month,&day);
for(i=1;i<month;i++)
{
/**********Program**********/
switch(i){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10: days+=31;break;
case 2: days+=(28 + (year%4==0&&year%100!=0 || year%400==0?1:0));break;
default: days+=30;
}
/********** End **********/
}
printf("%d-%d-%d是该年第%d天\n",year,month,day,days + day);
}
@@ -0,0 +1,32 @@
/*------------------------------------------------------------------------
【程序设计】请编写函数sum,其功能是:用While循环语句求1到n之间(包括n)能
被3整除的所有整数之和,并将结果返回给主函数。(n值由主函数传入)
运行程序后若输入:10,则输出为:18
----------------------------------------------------------------------*/
#include "stdio.h"
long sum(int n)
{
/**********Program**********/
int i, s=0;
for(i=1;i<=n;i++){
if(i%3==0){
s+=i;
}
}
return s;
/********** End **********/
}
void main()
{
int x;
long f;
scanf("%d",&x);
f=sum(x);
printf("%ld\n",f);
}
@@ -0,0 +1,31 @@
/*-------------------------------------------------------
功能:设计程序打印出如下图案(菱形)
*
***
*****
*******
*****
***
*
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j,k;
/**********Program**********/
for(i=-3;i<=3;i++){
for(j=0;j<(i<0?-i:i);j++){
printf(" ");
}
for(k=0;k<7-j*2;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
}
@@ -0,0 +1,19 @@
/*------------------------------------------------------
题目:从键盘输入一个整数n,求2 至 n-1内所有能被n整除的数。
例如:输入10 输出 2 5
输入99 输出 3 9 11 33
--------------------------------------------------------*/
#include "stdio.h"
int main ( )
{
int n,i;
printf("input a number:");
scanf ("%d", &n);
/**********Program**********/
for(i=2;i<n;i++)
if(n%i==0)
/********** End **********/
printf ("%d\n",i);
}
@@ -0,0 +1,19 @@
/*-------------------------------------------------------
【程序填空】 2、有一箱苹果(100—200之间),如果分成4个苹果一组的若干组,则多2个苹果;若分成7个苹果一组,则多3个苹果; 若分成9个苹果一组,则多5个苹果,编程实现求苹果的个数。
--------------------------------------------------------*/
# include <stdio.h>
main ()
{
int i;
for(i=100;i<200;i++)
/**********Program**********/
if(i%4==2 && i%7==3 && i%9==5)
/********** End **********/
printf ("%d",i);
}
@@ -0,0 +1,23 @@
/*-------------------------------------------------------
【程序填空】---------------------------------------------------------
功能:计算武汉城区出租车收费的程序,当里程在3公里以内含3公里时收费12元,超过3公里(在0和1之间均计1公里)的部分每公里收费2元。
备注:使用switch来实现
--------------------------------------------------------*/
#include<stdio.h>
main(){
int m,n;
scanf("%d",&m);
/**********Program**********/
n=0;
switch(m){
default: n+=(m-3)*2;
case 1:
case 2:
case 3:n+=12;
}
/********** End **********/
printf("本次收费为:%d",n);
}
@@ -0,0 +1,22 @@
/*-------------------------------------------------------
功能:从键盘输入2个整数相加,再输入答案,如果正确,显示"right",否则显示"error"。
--------------------------------------------------------*/
#include "stdio.h"
main( )
{
int a,b,c;
printf("please input a and b:\n");
scanf("%d,%d",&a , &b);
printf("please input the answer:\n");
scanf("%d",&c);
/**********Program**********/
if(a+b==c)
/********** End **********/
printf("right\n");
else
printf("error\n");
}
@@ -0,0 +1,24 @@
/*-------------------------------------------------------
功能:功能:输入三角形的三边长,判断能否构成三角形,若能,利用海伦公式计
算该三角形的面积,计算结果保留3位小数。
l=(a+b+c)/2s=sqrt(l*(l-a)*(l-b)*(l-c))
--------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
float a,b,c,s,l;
scanf("%f,%f,%f",&a , &b , &c);
if(a+b<c||a+c<b||b+c<a)
printf("该3个数据不能构成三角形\n");
else
{
/**********Program**********/
l=(a+b+c)/2;
s=sqrt(l*(l-a)*(l-b)*(l-c));
/********** End **********/
printf("该三角形的面积为%.3f\n",s);
}
}
@@ -0,0 +1,20 @@
/*-------------------------------------------------------
编程计算:s=1×2×3×……×n (n由键盘输入,使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,n,p;
p=1;
printf("请输入一个正整数n:");
scanf("%d",&n);
/**********Program**********/
for(i=2;i<=n;i++){
p*=i;
}
/********** End **********/
printf("1*2*...*%d = %d\n",n,p);
}
@@ -0,0 +1,23 @@
/*-------------------------------------------------------
编程计算:s=1!+3!+5!+…n! n由键盘输入,使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j,n;
long p,sum;
sum=0;
printf("请输入一个正整数n:");
scanf("%d",&n);
/**********Program**********/
p = 1;
for ( i = 1;i <= n; i++ ) {
p *= i;
if ( i%2 == 1 ) {
sum += p;
}
}
/********** End **********/
printf("1!+3!+...+%d!= %d\n",n,sum);
}
@@ -0,0 +1,25 @@
/*-------------------------------------------------------
编程计算求e近似值:
用while语句求直到最后一项值小于10-5为止。
e=0+1+1/1+1/1/2+1/1/2/3...
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i;
double t,e;
i=1;
t=1.0;
e=0;
/**********Program**********/
e = 2;
i = 2;
while(t/i > 1e-5){
e += t/i;
t /= i++;
}
/********** End **********/
printf("e=%f\n",e);
}
@@ -0,0 +1,21 @@
/*-------------------------------------------------------
编程计算求e近似值: 用for语句求前50项之和。
e=0+1+1/1+1/1/2+1/1/2/3...
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i;
double t,e;
t=1.0;
e=0;
for(i=1;i<=50;i++)
{
/**********Program**********/
e += t;
t /= i;
/********** End **********/
}
printf("前50项之和为:%f\n",e);
}
@@ -0,0 +1,24 @@
/*-------------------------------------------------------
功能:输入一个圆半径(r),当r>=0时,计算并输出圆的面积(area)和周长(circumference),否则,输出提示信息。
--------------------------------------------------------*/
#include <stdio.h>
#define PI 3.14
main()
{
float r,s,l;
printf("please input r:\n");
scanf("%f",&r);
if (r>=0)
{
/**********Program**********/
s = PI * r*r;
l = 2*PI*r;
/********** End **********/
printf("the area is %f\n",s);
printf("the circumference is %f\n",l);
}
else
printf("input error!\n");
}
@@ -0,0 +1,24 @@
/*-------------------------------------------------------
功能:编写程序输入三位数(100-999),然后按数字逆序输出。(例:输入456↙,输出654)。
--------------------------------------------------------*/
#include <stdio.h>
void main()
{
int n,ge,shi,bai;
printf("请输入一个三位正整数:");
scanf("%d",&n);
if((n<100)||(n>999))
printf("输入数据有误!\n");
else
{
/**********Program**********/
ge = n % 10;
shi = n % 100 / 10;
bai = n / 100;
/********** End **********/
printf("此数的逆序输出结果为:%d%d%d\n",ge,shi,bai);
}
}
@@ -0,0 +1,21 @@
/*-------------------------------------------------------
编程计算:s=1!+2!+3!+…n! n由键盘输入,使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j,n;
long p,sum;
sum=0;
printf("请输入一个正整数n:");
scanf("%d",&n);
/**********Program**********/
p = 1;
for( i = 1;i <= n; i++ ){
p *= i;
sum += p;
}
/********** End **********/
printf("1!+2!+...+%d!= %d\n",n,sum);
}
@@ -0,0 +1,22 @@
/*-------------------------------------------------------
编程计算:s=1-3+5-7+……-99(使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,f,sum;
f=1;
sum=0;
/**********Program**********/
for(i=1;i<=99;i++){
if(i%2==1){
sum += i*f;
f*=-1;
}
}
/********** End **********/
printf("1-3+5-7+...-99 = %d\n",sum);
}
@@ -0,0 +1,29 @@
/*-------------------------------------------------------
功能:编写一个简单计算器程序,输入格式为:a op b。其中 a和b是
参加运算的两个数,op 为运算符,它的取值只能是+、-、*、/。
例:(注意输出格式)
输入:3+4
输出:3.000000+4.000000=7.000000
--------------------------------------------------------*/
#include<stdio.h>
main()
{
float a,b;
char op;
printf("Please enter a,b and op:");
scanf("%f,%c,%f",&a,&op,&b);
switch(op)
{
/**********Program**********/
case '+':printf("%f+%f=%f\n", a, b, a+b);break;
case '-':printf("%f-%f=%f\n", a, b, a-b);break;
case '*':printf("%f*%f=%f\n", a, b, a*b);break;
/********** End **********/
case '/':if(b!=0)
printf("%f/%f=%f\n",a,b,a/b);
else
printf("error!\n");break;
default:printf("error!\n");break;
}
}
@@ -0,0 +1,20 @@
/*-------------------------------------------------------
功能:编写程序,把三个整数中最大的打印出来。
--------------------------------------------------------*/
#include"stdio.h"
main()
{
int a,b,c,m;
scanf("%d,%d,%d", &a,&b,&c);
/**********Program**********/
m = a;
if( b > m ){
m = b;
}
if ( c > m ) {
m = c;
}
/********** End **********/
printf ("m=%d\n",m);
}
@@ -0,0 +1,28 @@
/*-------------------------------------------------------
功能::使用for循环打印出如下图案(菱形)
*
***
*****
*******
*****
***
*
--------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j,k;
/**********Program**********/
for(i=-3;i<=3;i++){
for(j=0;j<(i<0?-i:i);j++){
printf(" ");
}
for(k=0;k<7-j*2;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
}
@@ -0,0 +1,24 @@
/*-------------------------------------------------------
编程计算π的近似值(直到最后一项的绝对值小于10-5为止),要求保留小数点后10位: (使用while)
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,f;
double t,s;
f=1;
s=0;
i=1;
t=1.0;
/**********Program**********/
while(fabs(t/i)>1e-5){
s+=t/i*f;//计算该项的值
f*=-1;//翻转符号
i+=2;
}
/********** End **********/
s=s*4;
printf("圆周率的近似值为:%.10f\n",s);
}
@@ -0,0 +1,27 @@
/*-------------------------------------------------------
功能:找出n个数中最大的数和最小的数,并将它们的值输出出来。
--------------------------------------------------------*/
#include<stdio.h>
int main()
{
int a,n,i,min,max;
scanf("%d",&n);
scanf("%d",&a);
min=a;
max=a;
for(i=1;i<n;i++)
{
/**********Program**********/
scanf("%d", &a);
if(a > max){
max = a;
}
if(a < min){
min = a;
}
/********** End **********/
}
printf("The maximum number is %d.\n",max);
printf("The minimum number is %d.\n",min);
}
@@ -0,0 +1,28 @@
/*-------------------------------------------------------
编程计算π的近似值(直到最后一项的绝对值小于10-5为止,使用while):
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
#define N 1e-5
main()
{
int i,f;
double t,s;
f=1;
s=0;
i=1;
t=1.0;
/**********Program**********/
while(fabs(t/i)>N){
s+=t/i*f;//计算该项的值
f*=-1;//翻转符号
i+=2;
}
/********** End **********/
s=s*4 ;
printf("圆周率的近似值为:%f\n",s);
}
@@ -0,0 +1,17 @@
/*-------------------------------------------------------
功能:编程实现求1-10(包含1,不包含10)之间的所有数的乘积并输出。(使用while)
--------------------------------------------------------*/
#include <stdio.h>
main( )
{
int i=1, sum=1;
/**********Program**********/
while(i<10){
sum*=i;
i++;
}
/********** End **********/
printf("the sum of odd is :%d\n",sum);
}
@@ -0,0 +1,29 @@
/*-------------------------------------------------------
功能:从键盘上输入若干个学生的成绩,统计并输出最高成绩和最
低成绩,当输入负数时结束输入。(使用while循环)
--------------------------------------------------------*/
#include <stdio.h>
main()
{
int x,max,min;
printf("please input x:\n");
scanf("%d",&x);
max=x;
min=x;
/**********Program**********/
while(x > 0){
if(x > max){
max = x;
}
if(x < min){
min = x;
}
scanf("%d", &x);
}
/********** End **********/
printf("max=%d,min=%d\n",max,min);
}
@@ -0,0 +1,20 @@
/*-------------------------------------------------------
编程计算:使用for计算,s=1+2+3+……+n n由键盘输入)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,n,sum;
sum=0;
printf("请输入一个正整数n:");
scanf("%d",&n);
/**********Program**********/
for(i=1;i<=n;i++){
sum+=i;
}
/********** End **********/
printf("1+2+...+%d = %d\n",n,sum);
}
@@ -0,0 +1,21 @@
/*-------------------------------------------------------
功能:编写比较a、b两个数的大小,且把大者赋给max,小者赋给min。
--------------------------------------------------------*/
#include"stdio.h"
main()
{
int a,b,min,max;
printf("输入两个数给a,b:");
scanf("%d,%d",&a,&b);
/**********Program**********/
if (a > b) {
max = a;
min = b;
} else {
max = b;
min = a;
}
/********** End **********/
printf("min=%d,max=%d\n",min,max);
}
@@ -0,0 +1,27 @@
/*-------------------------------------------------------
功能:输入三个整数x,y,z,请把这三个数由小到大输出。
--------------------------------------------------------*/
#include <stdio.h>
main()
{
int x,y,z,t;
scanf("%d%d%d",&x , &y , &z);
/**********Program**********/
if (x > y) {
t = x;
x = y;
y = t;
}
if (y > z) {
t = y;
y = z;
z = t;
}
if (x > y) {
t = x;
x = y;
y = t;
}
/********** End **********/
printf("small to big: %d %d %d\n",x,y,z);
}
@@ -0,0 +1,19 @@
/*-------------------------------------------------------
功能:从键盘输入整数n,输出n以内所有奇数的和。(使用for循环)
--------------------------------------------------------*/
#include<stdio.h>
void main()
{
int n,i,s;
s=0;
scanf("%d",&n);
/**********Program**********/
for(i=1;i<=n;i++){
if(i%2==1){
s+=i;
}
}
/********** End **********/
printf("s=%d\n",s);
}
@@ -0,0 +1,34 @@
/*-------------------------------------------------------
任意输入一个日期,计算这一天是这一年中的第几天(考虑闰年和平年)。
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int y,m,d,s,f;
s=0;
printf("请输入一个日期(YYYY-MM-DD):");
scanf("%d-%d-%d",&y,&m,&d);
if(y%4==0&&y%100!=0||y%400==0)
f=1;
else
f=0;
switch(m-1)
{
/**********Program**********/
case 11: s+=30;
case 10: s+=31;
case 9: s+=30;
case 8: s+=31;
case 7: s+=31;
case 6: s+=30;
case 5: s+=31;
case 4: s+=30;
case 3: s+=31;
case 2: s+=f+28;
case 1: s+=31;
/********** End **********/
}
s=s+d ;
printf("%d-%d-%d是这一年中的第%d天\n",y,m,d,s);
}
@@ -0,0 +1,49 @@
/*-------------------------------------------------------
求前100个素数,输出时每个数占5个字符宽度,10个一行,并输出其平均值。
结果:
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223 227 229
233 239 241 251 257 263 269 271 277 281
283 293 307 311 313 317 331 337 347 349
353 359 367 373 379 383 389 397 401 409
419 421 431 433 439 443 449 457 461 463
467 479 487 491 499 503 509 521 523 541
average=241.330000
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j,k,m,sum;
double avg;
k=0;
sum=0;
for(i=2;k<100;i++)
{
m=sqrt(i);
/**********Program**********/
for(j=2;j<=m;j++){
if(i%j==0){
break;
}
}
if(j>m){
printf("%5d", i);
k++;
sum+=i;
if(k%10==0){
printf("\n");
}
}
/********** End **********/
}
avg=sum/100.0;
printf("\naverage=%f\n",avg);
}
@@ -0,0 +1,32 @@
/*-------------------------------------------------------
求100到200间的所有素数,输出时每个数占5个字符宽度,10个一行。要求在奇数中找素数。
结果:
101 103 107 109 113 127 131 137 139 149
151 157 163 167 173 179 181 191 193 197
199
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j,k,m;
k=0;
for(i=101;i<200;i+=2 )
{
m=sqrt(i);
/**********Program**********/
for(j=2;j<=m;j++){
if(i%j==0){
break;
}
}
if(j > m){
printf("%5d", i);
k++;
if(k%10==0){
printf("\n");
}
}
/********** End **********/
}
}
@@ -0,0 +1,31 @@
/*-------------------------------------------------------
使用for循环输出99乘法表,要求格式如图所示: (注:乘积占四个字符)
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9
2x1=2 2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18
3x1=3 3x2=6 3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27
4x1=4 4x2=8 4x3=12 4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25 5x6=30 5x7=35 5x8=40 5x9=45
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36 6x7=42 6x8=48 6x9=54
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 7x8=56 7x9=63
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 8x9=72
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
/**********Program**********/
for(i=1;i<10;i++){
for(j=1;j<10;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}
@@ -0,0 +1,31 @@
/*-------------------------------------------------------
编写程序打印一个n行的菱形,n由键盘输入
输入:5
输出:
*
***
*****
***
*
-----------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j,k,n;
printf("请输入一个奇数(行数)n:");
scanf("%d",&n);
for(i=-n/2; i<=n/2;i++)
{
/**********Program**********/
for(j=0;j<abs(i);j++){
printf(" ");
}
for(k=0;k<n-j*2;k++){
printf("*");
}
printf("\n");
/********** End **********/
}
}
@@ -0,0 +1,19 @@
/*-------------------------------------------------------
编程输出500以内的“水仙花数”。“水仙花数”是一个三位数,其各位数字立方和等于该数本身(例:153=13+53+33)。(使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b,c,i;
/**********Program**********/
for(i=100;i<500;i++){
a = i%10;
b = i%100/10;
c = i/100;
if(a*a*a + b*b*b + c*c*c == i)
/********** End **********/
printf("%d\n",i);
}
}
@@ -0,0 +1,30 @@
/*-------------------------------------------------------
斐波那契数列的前几项是:1、1、2、3、5、8、13、21……编程输出该数列,直到某项的值大于10000为止,每行输出4个。
结果:
1 1 2 3
5 8 13 21
34 55 89 144
233 377 610 987
1597 2584 4181 6765
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b,c,i;
a=b=1;
printf("%d\t%d\t",a,b);
for(i=3;;i++)
{
c=a+b;
if(c>10000)
break;
printf("%d\t",c);
/**********Program**********/
if(i%4==0){
printf("\n");
}
a = b;
b = c;
}
/********** End **********/
}
@@ -0,0 +1,29 @@
/*-------------------------------------------------------
斐波那契数列的前几项是:1、1、2、3、5、8、13、21……编程输出该数列的前20项,每行输出4个。
结果:
1 1 2 3
5 8 13 21
34 55 89 144
233 377 610 987
1597 2584 4181 6765
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b,c,i;
a=b=1;
printf("%d\t%d\t",a,b);
for(i=3;i<=20;i++)
{
c=a+b;
printf("%d\t",c);
/**********Program**********/
if(i%4==0){
printf("\n");
}
a = b;
b = c;
/********** End **********/
}
}
@@ -0,0 +1,28 @@
/*-------------------------------------------------------
使用for循环输出99乘法表,要求格式如图所示:(注:格式 %dx%d=%-4d)
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9
2x1=2 2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16
3x1=3 3x2=6 3x3=9 3x4=12 3x5=15 3x6=18 3x7=21
4x1=4 4x2=8 4x3=12 4x4=16 4x5=20 4x6=24
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24
7x1=7 7x2=14 7x3=21
8x1=8 8x2=16
9x1=9
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
/**********Program**********/
for(i = 1;i<10;i++){
for(j=1;j<=10-i;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}
@@ -0,0 +1,34 @@
/*-------------------------------------------------------
使用for循环输出99乘法表,要求格式如图所示:
1x9=9
2x8=16 2x9=18
3x7=21 3x8=24 3x9=27
4x6=24 4x7=28 4x8=32 4x9=36
5x5=25 5x6=30 5x7=35 5x8=40 5x9=45
6x4=24 6x5=30 6x6=36 6x7=42 6x8=48 6x9=54
7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 7x8=56 7x9=63
8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 8x9=72
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
for(i=1;i<=9;i++)
{
for(j=1;j<10-i;j++)
{
printf("\t");
}
/**********Program**********/
for(j=10-i;j<10;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}
@@ -0,0 +1,31 @@
/*-------------------------------------------------------
使用for循环输出99乘法表,要求格式如图所示:
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9
2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18
3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27
4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36
5x5=25 5x6=30 5x7=35 5x8=40 5x9=45
6x6=36 6x7=42 6x8=48 6x9=54
7x7=49 7x8=56 7x9=63
8x8=64 8x9=72
9x9=81
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
for(i=1;i<=9;i++)
{
for(j=1;j<i;j++)
{
printf("\t");
}
/**********Program**********/
for(j=i;j<10;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}
@@ -0,0 +1,24 @@
/*-------------------------------------------------------
编程求s=a+aa+aaa+aaaa+aa…a的值。其中a为一个数字,例:3+33+333+3333+33333,要求a以及所加数字个数n由键盘输入,示例中a=3,n=5。(注:使用for
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,n,s,i,t;
s=t=0;
printf("请输入数字a:");
scanf("%d",&a);
printf("请输入求和的项数n:");
scanf("%d",&n);
/**********Program**********/
t = a;
for(i=0;i<n;i++){
s += t;
t*=10;
t+=a;
}
/********** End **********/
printf("s=%d\n",s);
}
@@ -0,0 +1,26 @@
/*-------------------------------------------------------
请编写输出以下图案的程序。(注意:需要使用math库abs)
1
123
12345
1234567
12345
123
1
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j;
for(i=-3;i<=3;i++)
{
/**********Program**********/
for(j=0;j<7-abs(i)*2;j++){
printf("%d", j+1);
}
printf("\n");
/********** End **********/
}
}
@@ -0,0 +1,21 @@
/*-------------------------------------------------------
从键盘输入一个十进制整数,将其转换为二进制后反序再转成新的十进制后输出。(例:11→1011→1101→13)(注:使用while循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int n,s,t;
s=0;
printf("请输入一个整数:");
scanf("%d",&n);
/**********Program**********/
//1011 从最末尾开始 依次除出
//加入s之前将前加入的数*1
while(n){
s += s + n%2;
n /= 2;
}
/********** End **********/
printf("%d\n",s);
}
@@ -0,0 +1,23 @@
/*-------------------------------------------------------
编程判断m是否素数,m由键盘输入。(使用for)
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int m,i,k;
printf("请输入一个正整数 :");
scanf("%d",&m);
k=sqrt(m);
/**********Program**********/
for(i=2;i<=k;i++){
if(m % i == 0){
break;
}
}
/********** End **********/
if(i>k)
printf("%d是素数\n",m);
else
printf("%d不是素数\n",m);
}
@@ -0,0 +1,22 @@
/*-------------------------------------------------------
编程判断m是否素数,m由键盘输入。(使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int m,i;
printf("请输入一个正整数 :");
scanf("%d",&m);
/**********Program**********/
for(i=2;i<m;i++){
if(m%i==0){
break;
}
}
/********** End **********/
if(i==m)
printf("%d是素数\n",m);
else
printf("%d不是素数\n",m);
}
@@ -0,0 +1,30 @@
/*-------------------------------------------------------
使用for循环输出99乘法表,要求格式如图所示: (注:乘积占四个字符)
1x1=1
2x1=2 2x2=4
3x1=3 3x2=6 3x3=9
4x1=4 4x2=8 4x3=12 4x4=16
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
/**********Program**********/
for(i=1;i<10;i++){
for(j=1;j<=i;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}
@@ -0,0 +1,29 @@
/*-------------------------------------------------------
从键盘输入5个整数,输出其最大值、最小值、平均值。(注:使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int n,s,max,min,i;
double avg;
scanf("%d",&n);
s=max=min=n;
for(i=2;i<=5;i++)
{
scanf("%d",&n);
/**********Program**********/
if(n > max){
max = n;
}
if(n < min){
min = n;
}
s+=n;
/********** End **********/
}
avg=s/5.0;
printf("max=%d,min=%d,avg=%f\n",max,min,avg);
}

Some files were not shown because too many files have changed in this diff Show More