程序改錯(cuò)
/*------------------------------------------------------
【程序改錯(cuò)】
--------------------------------------------------------
函數(shù)fun的功能是:求1到20的階乘的和。
--------------------------------------*/
#include "stdio.h"
main ()
{
int n,j;
float s=0.0,t=1.0;
for(n=1;n<=20;n++)
{
/**********ERROR**********/
s=1;
for(j=1;j<=n;j++)
/**********ERROR**********/
t=t*n;
/**********ERROR**********/
s+t=s;
}
printf("jiecheng=%f\n",s);
}
【改錯(cuò)1】
【參考答案】
t=1;
t=1.0;
============================================================
【改錯(cuò)2】
【參考答案】
t= t * j ;
t*=j;
t=j*t;
============================================================
【改錯(cuò)3】
【參考答案】
s= s + t ;
s+=t;
s=t+s;
============================================================
/*------------------------------------------------------
【程序改錯(cuò)】
--------------------------------------------------------
功能:實(shí)現(xiàn)兩個(gè)字符串的連接。
例如:輸入dfdfqe和12345時(shí),則輸出dfdfqe12345.
------------------------------------------------------*/
#include"stdio.h"
main()
{
char s1[80],s2[80];
void scat(char s1[],char s2[]);
gets(s1);
gets(s2);
scat(s1,s2);
puts(s1);
}
void scat (char s1[],char s2[])
{
int i=0,j=0;
/**********ERROR**********/
while(s1[i]= ='\0') i++;
/**********ERROR**********/
while(s2[j]= ='\0')
{
/**********ERROR**********/
s2[j]=s1[i];
i++;
j++;
}
/**********ERROR**********/
s2[j]='\0';
}
【改錯(cuò)1】
【參考答案】
while(s1[i]!='\0')i++;
while(s1[i])i++;
while(s1[i]!=NULL)i++;
while(s1[i]!=0)i++;
============================================================
【改錯(cuò)2】
【參考答案】
while(s2[j]!='\0')
while(s2[j])
while(s2[j]!=NULL)
while(s2[j]!=0)
============================================================
【改錯(cuò)3】
【參考答案】
s1[i]=s2[j];
============================================================
【改錯(cuò)4】
【參考答案】
s1[i]='\0';
s1[i]=NULL;
*(s1+i)='\0';
s1[i]=0;
2015年全國(guó)職稱計(jì)算機(jī)考試教材(2007模 .. 定價(jià):¥225 優(yōu)惠價(jià):¥213 更多書(shū)籍 | |
全國(guó)職稱計(jì)算機(jī)考試速成過(guò)關(guān)系列套裝:W .. 定價(jià):¥133 優(yōu)惠價(jià):¥133.0 更多書(shū)籍 |