编程语言
首页 > 编程语言> > 第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);
}

 

标签:include,return,int,max,编程,第四版,printf,习题,main
来源: https://www.cnblogs.com/mljrm/p/15531852.html