啊哈!C语言课后参考答案上

最近看到一本好评量很高的的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("*
");
    printf("**
");
    printf("***
");
    system("pause");
    return 0;
}
  *
 * *
*   *
 * *
  * 
#include <stdio.h>
#include <stdlib.h>
int main()
{
    printf("  *
");
    printf(" * *
");
    printf("*   *
");
    printf(" * *
");
    printf("  *
");
    
    system("pause");
    return 0;
}  
        *
       *
      *
 *   *
  **
   * 
#include <stdio.h>
#include <stdlib.h>
int main()
{
    printf("       *
");
    printf("      *
");
    printf("     *
");
    printf("*   *
");
    printf(" **
");
    printf("  *
");
    system("pause");
    return 0;
}

//显示如下图形
#include <stdio.h>
#include <stdlib.h>
int main()
{
    printf("A
");
    printf("BC
");
    printf("DEF
");
    printf("GHIJ
");
    printf("KLMNO
");
    printf("PRSTUV
");
    printf("W
");
    printf("X
");
    printf("Y
");
    printf("Z
");
    system("pause");
    return 0;
}
//打印一个小飞机(绿底白字)
#include <stdio.h>
#include <stdlib.h>
int main()
{
    system("color 2f");
    printf("      *
");
    printf("      **
");
    printf("*     ***
");
    printf("**    ****
");
    printf("***************
");
    printf("**    ****
");
    printf("*     ***
");
    printf("      **
");
    printf("      *
");
    system("pause");
    return 0;
}
//打印一个小红旗(白底红字)
#include <stdio.h>
#include <stdlib.h>
int main()
{
    system("color f4");
    printf("A
");
    printf("I*
");
    printf("I**
");
    printf("I***
");
    printf("I****
");
    printf("I*****
");
    printf("I
");
    printf("I
");
    printf("I
");
    printf("I
");
    system("pause");
    return 0;
}
//第四节
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a,b,c;
    a=5;
    b=3;
    c=1;
    printf("%d
",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
",a+b);
    int c,d;
    c=7078;
    d=8712;
    printf("%d
",c*d);
    int e,f;
    e=321;
    f=123456+54321;
    printf("%d
",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
",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
",c);
    float d,e,f;
    d=1.1*100;
    printf("%f
",d);
    e=10.1;
    f=10*10;
    printf("%f
",e*f);
    system("pause");
    return 0;
}
//指定两个数,输出这两个数的和、差、积、商,例如,这两个数是9和3,输出他们的和、差、商、积
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a=9,b=3;
    printf("%d
",a+b);
    printf("%d
",a-b);
    printf("%d
",a*b);
    printf("%d
",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
");
    }
    if(a<0){
        printf("no
");
    }
    if(a==0){
        printf("0
");
    }
    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("
");
        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("
");
        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
");
        b = 1; 
        while(b <= a) {
            printf(" "); 
            b = b+1;
        }            
        printf("<H>
");
        b = 1; 
        while(b <= a) {
            printf(" "); 
            b = b+1;
        }
        printf("I I
");
        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("
");
    }
    
    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("
");
    }      
    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("
");
    }      
    system("pause"); 
    return 0;
}
欢迎查阅
原文地址:https://www.cnblogs.com/gh110/p/12158129.html