@@ -1244,6 +1244,77 @@ int main()
1244
1244
* (4)单链表基本算法实现程序
1245
1245
设计要求:定义单链表数据结构、实现单链表的建立、销毁、查找、插入、删除、排序算法、利用单链表的算法实现多项式相加减应用。
1246
1246
1247
+ > 本人选择的是计算器程序设计,参考材料并进行改进写出如下代码,以下代码仅为计算机核心运算脚本。但由于知识匮乏,本人无法绘制出可视化图形界面,敬请谅解。如有大神能够完整制作出该程序,欢迎改进如下代码。
1248
+ ```
1249
+ #include <stdio.h>
1250
+ #include <math.h>
1251
+ #pragma warning(disable : 4996)
1252
+ void main(void)
1253
+ {
1254
+ int c = 1;
1255
+ float operationA = 0;
1256
+ float operationB = 0;
1257
+ int isContinue = 1;
1258
+ while (isContinue)
1259
+ {
1260
+ printf("请输入第一个运算数字:\t");
1261
+ scanf("%f", &operationA);
1262
+ printf("请选择你要进行的运算类型:1加法,2减法,3乘法,4除法,5平方,6开方\n");
1263
+ scanf("%d", &c);
1264
+ if (c < 1 || c>6)
1265
+ {
1266
+ printf("请正确选择运算!");
1267
+ break;
1268
+ }
1269
+ if (c ==1||c==2||c==3||c==4)
1270
+ {
1271
+ printf("请输入第二个运算数字:\t");
1272
+ scanf("%f", &operationB);
1273
+ }
1274
+ if (c == 1)
1275
+ {
1276
+ printf("%f + %f = %f\n", operationA, operationB, operationA + operationB);
1277
+ }
1278
+ else if (c == 2)
1279
+ {
1280
+ printf("%f - %f = %f\n", operationA, operationB, operationA - operationB);
1281
+ }
1282
+ else if (c == 3)
1283
+ {
1284
+ printf("%f * %f = %f\n", operationA, operationB, operationA * operationB);
1285
+ }
1286
+ else if (c == 4)
1287
+ {
1288
+ while (operationB == 0) {
1289
+ printf("除数不能为零!请重新输入第二个数:");
1290
+ scanf("%f", &operationB);
1291
+ }
1292
+ printf("%f / %f = %f\n", operationA, operationB, operationA / operationB);
1293
+ }
1294
+ else if (c == 5)
1295
+ {
1296
+ float medianvalue1 = 0;
1297
+ medianvalue1 = pow(operationA, 2);
1298
+ printf("%f", medianvalue1);
1299
+ }
1300
+ else if (c == 6)
1301
+ {
1302
+ float medianvalue2 = 0;
1303
+ medianvalue2 = sqrt(operationA);
1304
+ printf("%f", medianvalue2);
1305
+ }
1306
+ printf("\n\n");
1307
+ printf("你是否还要继续进行运算:是:1 否:0 \n");
1308
+ scanf("%d", &isContinue);
1309
+ if (isContinue == 0)
1310
+ {
1311
+ isContinue = 0;
1312
+ }
1313
+ }
1314
+
1315
+ }
1316
+ ```
1317
+
1247
1318
1248
1319
1249
1320
0 commit comments