C Primer Plus第六版第一二章原始碼

哇呼葫發表於2020-11-22
                           程式碼在codeblocks正常執行,供初學者學習。                       

程式清單1.1
#include <stdio.h>
int main(void)
{
int dogs;

printf("How many dogs do you have?\n");
scanf("%d",&dogs);
printf("so you have %d dog(s)!\n",dogs);

return 0;

}
程式清單1.2
#include <stdio.h>
int main(void)
{
printf(“Concrete contains gravel and cement.\n”);

return 0;

}
程式清單2.1
#include <stdio.h>
int main (void)
{
int num;
num=1;

printf("I an a simple");
printf("computer.\n");
printf("My favorite number is %d because it is first.\n",num);

return 0;

}
程式清單2.2
//fathm_ft.c–把2音尋轉換成英寸
#include <stdio.h>
int main(void)
{
int feet,fathoms;

fathoms=2;
feet=6*fathoms;
printf("There are %d feet in %d fathoms!\n",feet,fathoms);
printf("Yes,I said %d feet!\n",6*fathoms);

return 0;

}
程式清單2.3
//two_func.c–一個檔案中包含兩個函式/
#include <stdio.h>
void bulter(void);/ANSI/ISO C函式原型/
int main(void)
{
printf(“I will summon the bulter function.\n”);
bulter();
printf(“Yes.Bring me some tea and writable DVDS.\n”);

return 0;

}
void bulter(void)/函式定義開始/
{
printf(“You rang,sir?\n”);
}
程式清單2.4
/* nogood.c–有錯誤的程式*/
#include <stdio.h>
int main(void)
{
int n,int n2,int n3;

/*該程式有多處錯誤
n=5;
n2=n*n;
n3=n2*n2;
printf("n=%d,n squared=%d,n cubed=%d\n",n,n2,n3)

return 0;

}
程式清單2.5
/stillbad.c–修復了語法錯誤的程式/
#include <stdio.h>
int main(void)
{
int n,n2,n3;

/*該程式有一個語義錯誤*/
n=5;
n2=n*n;
n3=n2*n2;
printf("n=%d,n squares=%d,n cubbed=%d\n",n,n2,n3);

return 0;

}

相關文章