最近看到一本好評量很高的的C語言入門書,課本真的很好,入門的話。專業性沒有那么強,但入門足夠了!!好評!看着看着就想把這本書的題課后習題都寫出來,最后就有了這個小結。可能有的不是最好,不那么專業,但主要是以初學者的思維角度去寫。盡量讓初學者通俗易懂。
鏈接:https://pan.baidu.com/s/1nArPBm8nxCrj8awWQBglSw
提取碼:zlm8
鏈接:https://pan.baidu.com/s/1Yp4jGIwaput8WmrTyHKgMA
提取碼:u85y
從第二章開始
第二章
//2.2節
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("hi");
system("pause");
return 0;
}
//2題顯示如下圖形
*
**
***
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("*\n");
printf("**\n");
printf("***\n");
system("pause");
return 0;
}
*
* *
* *
* *
*
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf(" *\n");
printf(" * *\n");
printf("* *\n");
printf(" * *\n");
printf(" *\n");
system("pause");
return 0;
}
*
*
*
* *
**
*
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf(" *\n");
printf(" *\n");
printf(" *\n");
printf("* *\n");
printf(" **\n");
printf(" *\n");
system("pause");
return 0;
}
//顯示如下圖形
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("A\n");
printf("BC\n");
printf("DEF\n");
printf("GHIJ\n");
printf("KLMNO\n");
printf("PRSTUV\n");
printf("W\n");
printf("X\n");
printf("Y\n");
printf("Z\n");
system("pause");
return 0;
}
//打印一個小飛機(綠底白字)
#include <stdio.h>
#include <stdlib.h>
int main()
{
system("color 2f");
printf(" *\n");
printf(" **\n");
printf("* ***\n");
printf("** ****\n");
printf("***************\n");
printf("** ****\n");
printf("* ***\n");
printf(" **\n");
printf(" *\n");
system("pause");
return 0;
}
//打印一個小紅旗(白底紅字)
#include <stdio.h>
#include <stdlib.h>
int main()
{
system("color f4");
printf("A\n");
printf("I*\n");
printf("I**\n");
printf("I***\n");
printf("I****\n");
printf("I*****\n");
printf("I\n");
printf("I\n");
printf("I\n");
printf("I\n");
system("pause");
return 0;
}
//第四節
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c;
a=5;
b=3;
c=1;
printf("%d\n",a+b+c);
system("pause");
return 0;
}
//計算三個算式
//123456789+43214321
//7078*8712
//321*(123456+54321)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b;
a=123456789;
b=43214321;
printf("%d\n",a+b);
int c,d;
c=7078;
d=8712;
printf("%d\n",c*d);
int e,f;
e=321;
f=123456+54321;
printf("%d\n",e*f);
system("pause");
return 0;
}
//第五節
#include <stdio.h>
#include <stdlib.h>
int main()
{
float a,b,c;
a=5.2;
b=3.1;
c=a+b;
printf("%f\n",c);
system("pause");
return 0;
}
//計算下面三個式子
//1.2+2.3+3.4+4.5
//1.1*100
//10.1*(10*10)
#include <stdio.h>
#include <stdlib.h>
int main()
{
float a,b,c;
a=1.2+2.3;
b=3.4+4.5;
c=a+b;
printf("%f\n",c);
float d,e,f;
d=1.1*100;
printf("%f\n",d);
e=10.1;
f=10*10;
printf("%f\n",e*f);
system("pause");
return 0;
}
//指定兩個數,輸出這兩個數的和、差、積、商,例如,這兩個數是9和3,輸出他們的和、差、商、積
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=9,b=3;
printf("%d\n",a+b);
printf("%d\n",a-b);
printf("%d\n",a*b);
printf("%d\n",a/b);
system("pause");
return 0;
}
第三章
//第二節
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
scanf("%d",&a);
if(a<=100){
printf("yes");
}
system("pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
scanf("%d",&a);
if(a>0){
printf("yes\n");
}
if(a<0){
printf("no\n");
}
if(a==0){
printf("0\n");
}
system("pause");
return 0;
}
//第三節
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
scanf("%d",&a);
if(a%7==0){
printf("yes");
}
system("pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
scanf("%d",&a);
if(a%10==0){
printf("yes");
}
if(a%10!=0){
printf("no");
}
system("pause");
return 0;
}
//第四節
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
scanf("%d",&a);
if(a%10==7){
printf("yes");
}else{
printf("no");
}
system("pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
scanf("%d",&a);
if(a>=1&&a<=9){
printf("yes");
}else{
printf("no");
}
system("pause");
return 0;
}
//第五節
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
if(a==b){
printf("yes");
}else{
printf("no");
}
system("pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
if(a%b==0){
printf("yes");
}else{
printf("no");
}
system("pause");
return 0;
}
//第六節
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
scanf("%d",&a);
if(a%7==0||a%10==7){
printf("yes");
}else{
printf("no");
}
system("pause");
return 0;
}
//1、從鍵盤任意讀入3個整數,如何從中找出最小的一個?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c,d;
scanf("%d %d %d",&a,&b,&c);
if(a>b){
d=b;
}else{
d=a;
}
if(d>c){
d=c;
}
printf("%d",d);
system("pause");
return 0;
}
//2、從鍵盤任意讀入4個整數,如何從中找出最大的一個?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, c, d, e;
scanf("%d %d %d %d", &a, &b, &c, &d);
if(a > b) {
e = a;
}else{
e = b;
}
if(e < c) {
e = c;
}
if(e < d) {
e = d;
}
printf("%d", e);
system("pause");
return 0;
}
//3、從鍵盤輸入一個年份(整數),判斷這個年份是否為閏年,是 則輸出yes,不是則輸出no。
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
scanf("%d", &a);
if((a%4 == 0 && a%100 != 0) || a%400 == 0){
printf("yes");
}else{
printf("no");
}
system("pause");
return 0;
}
//第七節
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
scanf("%d", &a) ;
if (a%2==1){
printf("%d ", a+1) ;
printf("%d ", a+2) ;
printf("%d ", a+3) ;
}else{
printf("%d ", a-1) ;
printf("%d ", a-2) ;
printf("%d ", a-3) ;
}
system("pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
int a, b, c, d, t;
scanf("%d %d %d %d", &a, &b, &c, &d);
if(a > b) {
t = a;
a = b;
b = t;
}
if(a > c) {
t = a;
a = c;
c = t;
}
if(a > d) {
t = a;
a = d;
d = t;
}
if(b > c) {
t = b;
b = c;
c = t;
}
if(b > d) {
t = b;
b = d;
d = t;
}
if(c > d) {
t = c;
c = d;
d = t;
}
printf("%d %d %d %d", a, b, c, d);
system("pause");
return 0;
}
第四章
//第一節
//一起來找茬
while(1>0)
printf("hello");
//更進一步,動手試一試
while(1>0)
printf("你好");
//第 2 節
//一起來找茬
int a;
a=100;
while(a<=200){
printf("%d ",a);
a=a+1;
}
//更進一步,動手試一試
int a,b;
a=1;
while(a<=100){
printf("%d ",a);
a=a+1;
}
b=99;
while(b>=1){
printf("%d ",b);
b=b-1;
}
//第四節
//一起來找茬
int a,i;
a=1;
i=1;
while(i<=10)
{
a=a*i;
i=i+1;
}
printf("%d",a);
//更進一步,動手試一試
//1. 求1~100所有偶數的和。
int a,i;
a=0;
i=1;
while(i<=100){
if(i%2==0){
a=a+i;
}
i=i+1;
}
printf("%d",a);
//2. 輸入一個整數n(1<=n<=9),求n的階乘 [1] 。
int n,a,i;
scanf("%d",&n);
a=1;
i=1;
while(i<=n){
a=a*i;
i=i+1;
}
printf("%d",a);
//第五節
//更進一步,動手試一試
#include <stdio.h>
#include <stdlib.h>
#include<windows.h>
int main() {
int a, i, j;
a = 120;
while(a >= 0) {
system("cls");
i = a/60;
j = a%60;
if(j/10 == 0) {
printf("%d:0%d", i, j);
}
else
{
printf("%d:%d", i, j);
}
Sleep(1000);
a = a-1;
}
system("pause");
return 0;
}
//第六節
//更進一步,動手試一試
/*1.輸入一個整數n(1<=n<=30),當輸入的n值為3時,打印結果是: 1 2 2 3 3 3 當輸入的n值為6時,打印結果是: 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6*/
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, i, j;
scanf("%d", &n);
i = 1;
while(i <= n) {
j = 1;
while(j <= i) {
printf("%d ", i);
j = j+1;
}
printf("\n");
i = i+1;
}
system("pause");
return 0;
}
/*2.輸入一個整數n(1<=n<=30),當輸入的n值為3時,打印結果是: 1 2 3 4 5 6 當輸入的n值為5時,打印結果是: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15*/
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, i, j, k;
scanf("%d", &n);
k = 1;
i = 1;
while(i <= n) {
j = 1;
while(j <= i) {
printf("%d ", k);
k = k+1;
j = j+1;
}
printf("\n");
i = i+1;
}
system("pause");
return 0;
}
//第八節
/*更進一步,動手試一試 55 個“OK ” 1+2+3+4+5+6+7+8+9+10=55 */
//第九節
//類似於:從 1 打印到 100 和從 100 打印到 1。
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main() {
int a, b;
a = 10;
while(a >= 0) {
system("cls");
b = 1;
while(b <= a) {
printf(" ");
b = b+1;
}
printf(" O\n");
b = 1;
while(b <= a) {
printf(" ");
b = b+1;
}
printf("<H>\n");
b = 1;
while(b <= a) {
printf(" ");
b = b+1;
}
printf("I I\n");
Sleep(1000);
a = a-1;
}
system("pause");
return 0;
}
//第十節
//一起來找茬
#include <stdio.h>
#include <stdlib.h>
int main() {
int i, sum;
sum = 1;
for(i = 1; i <= 10; i++) {
sum = sum*i;
}
printf("%d", sum);
system("pause");
return 0;
}
//更進一步,動手試一試
/*1、請嘗試用for循環打印下面的圖形。 * *** ***** ******* ********* ******* ***** *** * */
#include <stdio.h>
#include <stdlib.h>
int main() {
int i, j, k, t;
for(i = 1; i <= 5; i++) {
for(j = 4; j >= i; j--) {
printf(" ");
}
for(k = 1; k <= 2*i-1; k++) {
printf("*");
}
printf("\n");
}
t = 7;
for(i = 1; i <= 4; i++) {
for(j = 1; j <= i; j++) {
printf(" ");
}
for(k = 1; k <= t; k++) {
printf("*");
}
t = t-2;
printf("\n");
}
system("pause");
return 0;
}
/*2、請嘗試用for循環來打印一個九九乘法表*/
#include <stdio.h>
#include <stdlib.h>
int main() {
int i, j;
for(i = 1; i <= 9; i++) {
for(j = 1; j <= i; j++) {
printf("%d*%d=%d ", i, j, i*j);
}
printf("\n");
}
system("pause");
return 0;
}