作业帮 > 综合 > 作业

一个用指针计算帽子尺寸的程序

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/25 14:54:13
一个用指针计算帽子尺寸的程序
#include #include
int main(void){ char size[3][12] = { { '6', '6', '6', '6', '7', '7', '7', '7', '7', '7','7','7' }, { '1', '5', '3', '7', ' ', '1', '1', '3', '1', '5', '3','7'}, { '2', '8', '4', '8', ' ', '8', '4', '8', '2', '8', '4', '8' } }; int headsize[12] = { 164, 166, 169, 172, 175, 178, 181, 184, 188, 191, 194, 197 };
char *psize = *size;/* *size前面要加*,如果只是size,表示s[0]中的元素,这样的元素有12个.加了*表示二维数组中s[0][0]中的值.所以*表示数组中不同的层次.*/ int *pheadsize = headsize;/* headsize表示指针变量存储一维数组中h[0]中的值.*/
float cranium = 0.0; int your_head = 0; bool hat_found = false; bool too_small = false;
printf("\nEnter the circumference of your head above your eyebrows in inches as a decimal value:"); scanf_s("%f", &cranium);
your_head = (int)(8.0*cranium);
for (int i = 0; i < 12; i++) { if (your_head>*(pheadsize + i)) continue;
if ((i == 0) && (your_head < (*pheadsize) - 1)) { printf("\nYou are the proverbian pinhead.No hat for you I'm afraid.\n"); too_small = true; break; } if (your_head < *(pheadsize + i) - 1) i--; printf("\nYour hat size is %c %c%c%c\n", *(psize + i), *(psize + 1 * 12 + i), (i == 4) ? ' ' : '/', *(psize + 2 * 12 + i)); hat_found = true; break; } if (!hat_found && !too_small) printf("\nYou,in tecnical parlance,are a fathead,no hat for you I'm afraid.\n"); return 0;}

请解释 if (your_head < *(pheadsize + i) - 1) i--;语句的意思.
她也同样起身,而当我倒下的时候
我们的灵魂在洪水上面的黑雨中赤裸地抖缩,
清酒同川,一脉起黄苍
太阳西沉,人就开始受煎熬,
飞啊,飞上西班牙的地图,
走走形式哈哈