C第48讲练习,试做失败,求详解
本帖最后由 欣欣celin 于 2014-5-1 18:35 编辑//本程序要实现查找,其中有不及格课程的学生,并打印其学号
#include "stdio.h"
void main()
{
double score[]={{60.0,70.0,80.5,90.5},{56.0,89.0,67.0,88.0},{34.2,78.5,90.0,70.5},{67.5,90.5,43.0,78.5}};
int i, j;
for(i=0; score != '\0'; i++)
{
for(j=0; score != '\0'; j++)
{
if(score < 60.0)
{
printf("score[%d][%d]", i, j);
}
}
}
}
以上写法怪怪的,CUP看了肯定2死了,可偶还不知错在哪了{:5_96:}
调试如下,
3: #include "stdio.h"
4: void main()
5: {
00401020 push ebp
00401021 mov ebp,esp
00401023 sub esp,0C8h
00401029 push ebx
0040102A push esi
0040102B push edi
0040102C lea edi,
00401032 mov ecx,32h
00401037 mov eax,0CCCCCCCCh
0040103C rep stos dword ptr
6: double score[]={{60.0,70.0,80.5,90.5},{56.0,89.0,67.0,88.0},{34.2,78.5,90.0,70.5},{67.5,90.5,43.0,78.5}};
0040103E mov dword ptr ,0
00401045 mov dword ptr ,404E0000h
0040104C mov dword ptr ,0
00401053 mov dword ptr ,40518000h
0040105A mov dword ptr ,0
00401061 mov dword ptr ,40542000h
00401068 mov dword ptr ,0
0040106F mov dword ptr ,4056A000h
00401076 mov dword ptr ,0
0040107D mov dword ptr ,404C0000h
00401084 mov dword ptr ,0
0040108B mov dword ptr ,40564000h
00401092 mov dword ptr ,0
00401099 mov dword ptr ,4050C000h
004010A0 mov dword ptr ,0
004010A7 mov dword ptr ,40560000h
004010AE mov dword ptr ,9999999Ah
004010B5 mov dword ptr ,40411999h
004010BC mov dword ptr ,0
004010C3 mov dword ptr ,4053A000h
004010CA mov dword ptr ,0
004010D1 mov dword ptr ,40568000h
004010D8 mov dword ptr ,0
004010DF mov dword ptr ,4051A000h
004010E6 mov dword ptr ,0
004010ED mov dword ptr ,4050E000h
004010F4 mov dword ptr ,0
004010FB mov dword ptr ,4056A000h
00401102 mov dword ptr ,0
00401109 mov dword ptr ,40458000h
00401110 mov dword ptr ,0
00401117 mov dword ptr ,4053A000h
7:
8: int i, j;
9:
10: for(i=0; score != '\0'; i++)
0040111E mov dword ptr ,0
00401128 jmp main+119h (00401139)
0040112A mov eax,dword ptr
00401130 add eax,1
00401133 mov dword ptr ,eax
00401139 mov ecx,dword ptr
0040113F shl ecx,5
00401142 lea edx,
00401146 mov eax,dword ptr
0040114C fld qword ptr
//运行到此,弹出对话框“unhandled exception in score.exe: 0xc0000005: access voilation",为什么?? 如何改才正确?
0040114F fcomp qword ptr
00401155 fnstsw ax
00401157 test ah,40h
0040115A jne main+1C3h (004011e3)
11: {
12: for(j=0; score != '\0'; j++)
00401160 mov dword ptr ,0
0040116A jmp main+15Bh (0040117b)
0040116C mov ecx,dword ptr
00401172 add ecx,1
00401175 mov dword ptr ,ecx
0040117B mov edx,dword ptr
00401181 shl edx,5
00401184 lea eax,
00401188 mov ecx,dword ptr
0040118E fld qword ptr
00401191 fcomp qword ptr
00401197 fnstsw ax
00401199 test ah,40h
0040119C jne main+1BEh (004011de)
13: {
14: if(score < 60.0)
0040119E mov edx,dword ptr
004011A4 shl edx,5
004011A7 lea eax,
004011AB mov ecx,dword ptr
004011B1 fld qword ptr
004011B4 fcomp qword ptr
004011BA fnstsw ax
004011BC test ah,1
004011BF je main+1BCh (004011dc)
15: {
16: printf("score[%d][%d]", i, j);
004011C1 mov edx,dword ptr
004011C7 push edx
004011C8 mov eax,dword ptr
004011CE push eax
004011CF push offset string "score[%d][%d]" (0042a0b0)
004011D4 call printf (004012f0)
004011D9 add esp,0Ch
17: }
18: }
004011DC jmp main+14Ch (0040116c)
19: }
004011DE jmp main+10Ah (0040112a)
20:
21: }
004011E3 pop edi
004011E4 pop esi
004011E5 pop ebx
004011E6 add esp,0C8h
004011EC cmp ebp,esp
004011EE call __chkesp (00401420)
004011F3 mov esp,ebp
004011F5 pop ebp
004011F6 ret
//还有,本题原本是要求用指针函数来解的,可是怎么也写不出来,越学越蒙了,咋办呐??
#include "stdio.h"
void main()
{
double score[]={{60.0,70.0,80.5,90.5},{56.0,89.0,67.0,88.0},{34.2,78.5,90.0,70.5},{67.5,90.5,43.0,78.5}};
int i, j;
for(i=0; i < 4; i++) // score != '\0'
{
for(j=0; j < 4; j++) // score != '\0'
{
if(score < 60.0)
{
printf("%.2lf ", score );
printf("score[%d][%d]\n", i, j);
}
}
}
} //本程序要实现查找,其中有不及格课程的学生,并打印其学号
#include "stdio.h"
void main()
{
double score[]={{60.0,70.0,80.5,90.5},{56.0,89.0,67.0,88.0},{34.2,78.5,90.0,70.5},{67.5,90.5,43.0,78.5}};
int i, j;
//for(i=0; score != '\0'; i++)
for(i=0; i<(sizeof(score)/sizeof(double)); i++)
{
//for(j=0; score != '\0'; j++)
for(j=0; j<4; j++)
{
if(score < 60.0)
{
printf("score[%d][%d]", i, j);
}
}
}
} 仰望天上的光 发表于 2014-4-30 20:51 static/image/common/back.gif
i<(sizeof(score)/sizeof(double))-------->不明白,有劳说明,感谢{:7_148:} 欣欣celin 发表于 2014-4-30 21:18 static/image/common/back.gif
i不明白,有劳说明,感谢
就是有几个学生,实在看不懂,换成4也可以 仰望天上的光 发表于 2014-4-30 21:44 static/image/common/back.gif
就是有几个学生,实在看不懂,换成4也可以
哦,谢谢{:5_110:}
页:
[1]