程序改错题new-答案(国外英文资料).docVIP

  • 6
  • 0
  • 约1.29万字
  • 约 36页
  • 2017-06-08 发布于河南
  • 举报
程序改错题new-答案(国外英文资料)

程序改错题new-答案(国外英文资料) 1. program debugging questions 1 (X_2_1.C) The following requirements: debugging procedures can not get the correct results, it contains 2 errors, please press the question of functional requirements, debug and modify the program (/*modified*/ on the modified statement after the notes), the operation can get the correct results. Save the results (including the X_2_1.C file and the X_2_1.EXE file) to the directory C:\KS\. Function Description: calculates the area of a circle with a radius of 1~n and prints only more than 50 of the area of the circle. For example, enter: 6 Then output: R=4, square=50.265488 R=5, square=78.539825 R=6, square=113.097351 Error primitive: #include stdio.h (main) { Int, R, n; Float area; Scanf (%d, n); For (r=1, r=n, r++) { Area=3.141593*r*r; If (area50.0) continue; Printf (r=%d, square=%d\n, R, area); } Getch (); } Answer #include stdio.h (main) { Int, R, n; Float area; Scanf (%d, n); For (r=1; r=n; r++) /*modified*/ { Area=3.141593*r*r; If (area50.0) continue; Printf (r=%d, square=%f\n, R, area); /*modified*/ } Getch (); } 2. program transfer questions 2 (X_2_2.C) The following requirements: debugging procedures can not get the correct results, it contains 3 errors, please press the question of functional requirements, debug and modify the program (/*modified*/ on the modified statement after the notes), the operation can get the correct results. Save the results (including the X_2_2.C file and the X_2_2.EXE file) to the directory C:\KS\. Function Description: the input decimal integer n through function DtoH converted to sixteen hexadecimal number, and the conversion results in string form output. Such as input: 79, output: 4F Input again: 1234 output: 4D2 Error primitive (see C:\KS\X_2_2.C): #include stdio.h Int DtoH (int, N, char, *str) { Int, I, d; For (i=0, N, =0, i++) { D=n%16; If (d=10) Str[i]=0+d; Else Str[i]=A+d-10; N/=16; } Return i; } (main) { Int, I, K, n; Char str[80]; Scanf (%d, n); K=DtoH (n, STR); For

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档