C primer plus复习及编程题

第二章 

C语言概述

1、复习题

1、C语言基本模块——函数
2、语法错误——不遵循C语言的规则(可用编译器检测出来)
3、语义错误——意思上的错误(编译器检测不出来)
4、
#include<stdio.h>
int main(void)//改成打印一年有多少周
{
	int s;
	s=56;
	printf("there are %d weeks in a year",s);
	//getchar();
	return 0;
}

5、
 a输出
         Baa Baa Black Sheep.Have you any wool?
 b输出
	 Begone!
	 0 creature of land!
 c输出
	 What?
	 No/nfish?
 d输出
	 2+2=4;
	 

6、关键字int、char

7、
int a=3020;
int b = 350;
printf("there were %d words and %d lines",a,b);

8.b=a=5;
#include<stdio.h>
int main(void)
{
	int a, b;
	a = 5;
	b = 2;
	b = a;
	a = b;
	printf("%d %d\n", b, a);
	return 0;
}

9、x=150;y=15;
#include<stdio.h>
int main(void)
{
	int x,y;
	x=10;
	y=5;
	y=x+y;//15
	x=x*y;//10*15=150
	printf("%d %d",x,y);
	return 0;
}

2、编程题

        1、
	printf("Gustav Mahler\n");
	printf("Gustav\nMahler\n");
	printf("Gustav ");
	printf("Mahler\n");


	2、
	printf("Name:Tu Hei\n");
	printf("Address:Najing instuate of techlogy\n");
	

        3、
	int age, days;
	scanf_s("%d", &age);
	days = 365 * age;
	printf("i am %d years old,totally %d days\n", age, days);
	
        4、
        #include<stdio.h>

        void jolly()
        {
    	    printf("For he is a jolly good fellow!\n");
        }

        void deny()
        {
            printf("Which nobody can deny!\n");
        }

        int main(void)
        {
	    jolly();
	    jolly();
	    jolly();
	    deny();
	    return 0;
        }

        5、
        #include<stdio.h>
        void br()
        {
	    printf("Brazil,Russia");
        }    
        void ic()
        {
	    printf("India,China");
        }
        int main(void)
        {
            br();
	    printf(",");
	    ic();
	    printf("\n");
	    ic();
	    printf(",\n");
	    br();
	    return 0;
        }
        
        6、#include<stdio.h>
        int main(void)
        {
	    int toes;
	    toes = 10;

            printf("%d ,%d,%d", toes, 2 * toes,toes*toes);
    	    return 0;
        }
     

        7、
        #include<stdio.h>
        void smile()
        {
	    printf("smile!");
        }
        int main(void)
        {
	    for (int i=0;i<3;i++)
	    {
		for (int j = 0; j <3-i; j++)
		{
		    smile();
		}
		printf("\n");
	}
	return 0;
        }

        8、
        #include<stdio.h>
        void one_three()
        {
	    printf("one\n");
        }
        void two()
        {
	    printf("two\n");
        }
        int main(void)
        {
	    printf("starting now:\n");
	    one_three();;
	    two();
	    printf("three\n");
	    printf("done!\n");
	    return 0;
        }

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值