Java教程

第1章(第四版)编程习题

本文主要是介绍第1章(第四版)编程习题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

P15

4

例1:输出This is a C program

#include<stdio.h>
int main()
{
    printf("This is a C program\n");
    return 0;
}

例2:求两个整数之和

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
    int a = 0;
    int b = 0;
    int sum = 0;
    scanf("%d%d",&a,&b);
    sum = a + b;
    printf("sum= %d\n",sum);
    return 0;
}

例3:求两个整数中最大值

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
    int a = 0;
    int b = 0;
    int max = 0;
    scanf("%d%d", &a, &b);
    max=(a>b?a:b);
    printf("max= %d\n", max);
    return 0;
}

5

输出信息

**************

Very good!

**************

#include<stdio.h>
int main()
{
    printf("**************\n");
    printf("Very good!\n");
    printf("**************\n");
    return 0;
}

6

输入a,b,c,输出最大值

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
    int a, b, c, max;
    printf("please input a,b,c:\n");
    scanf("%d,%d,%d",&a,&b,&c);
    max = a;
    if (max < b)
        max = b;
    if (max < c)
        max = c;
    printf("The largest number is %d\n", max);
    return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
    int max(int x, int y, int z);
    int a, b, c, d;
    scanf("%d %d %d", &a, &b, &c);
    d = max(a, b, c);
    printf("max = % d\n",d);
    return 0;
}
int max(int x, int y, int z)
{
    int g;
    if (x > y && x > z)
        g = x;
    else
        if (y > x && y > z)
            g = y;
        else
            if (z > x && z > y)
                g = z;
    return (g);
}

 

这篇关于第1章(第四版)编程习题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!