C Primer Plus课后编程习题

第二章

1.

//打印姓名
#include<stdio.h>
int main()
{
    printf("Gustav Mahler\n");
    printf("Gustav\n");
    printf("Mahler\n");
    printf("Gustav Mahler\n");
    return 0;
}

2.

//打印姓名和地址
#include<stdio.h>
int main()
{
    printf("Jack Ma\n");
    printf("CHINA\n");
    return 0;
}

3.

//输入年龄返回天数
#include<stdio.h>
int main()
{
    int i_age,i_days;
    printf("please type you age:\n");
    scanf("%d",&i_age);
    i_days = 365 * i_age;
    printf("convert to days is:%d",i_days);
    return 0;
}

4.

//调用函数进行打印
#include<stdio.h>

void jolly()
{   int i;
    for(i=0;i<3;i++)
        printf("For he is a jolly good fellow!\n");
}

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

int main()
{
    jolly();
    deny();
}

5.(两个子函数的内容不显示,已解决)【调用函数格式错误,前边不需要加void】

#include<stdio.h>

void br()
{
    printf("Brazil,Russia\n");
}

void ic()
{
    printf("India,China\n");
}

int main()
{
    printf("Brazil,Russia,India,China");
    void br();
    void ic();
}

6.(待排查,使用pow(toes,2)计算10的平方,输出为99;如果直接pow(10,2)正常,直接toes*toes也正常

#include<stdio.h>
#include<math.h>

int main()
{
    int toes = 10;
    int i_twice,i_square;
    i_twice = toes * 2;
    i_square = pow(toes,2);
    printf("The twice of toes is:%d\n",i_twice);
    printf("The square of toes is:%d\n",i_square);
    return 0;
}

7.

#include<stdio.h>

void joker()
{
    printf("Smile!");
}

//换行
void nn()
{
    printf("\n");
}

int main()
{
    joker();joker();joker();nn();
    joker();joker();nn();
    joker();nn();
}

8.

#include<stdio.h>

void one_three()
{
    printf("one\n");
    two();
    printf("three");

}

void two()
{
    printf("two\n");
}

int main()
{
    printf("starting now:\n");
    one_three();
    return 0;

}

第三章

1.

猜你喜欢

转载自www.cnblogs.com/lijitao/p/12114505.html