日常敲代码

好好学习,天天向上。今日练习小成果给大家分享一下
练习题一:求10个整数的最大值

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void main()
{
	int x, max, i;
	scanf("%d", &max);
	i = 1;
	do
	{
		scanf( "%d",&x );
		if (x > max) max = x;
		i = i + 1;
	}
	while (i <= 9);
	printf("max= %d", max);
	system("pause");

    }

练习题2 给定两个整型变量的值,将两个变量进行交换。

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void main()
{
	int a, b ,c;
	printf("请输入两个要交换的数:\n");
	scanf("%d %d", &a, &b);
	printf("交换前两个数:a=%d and b=%d\n", a,b);
	c = a;
	a = b;
	b = c;
	printf("交换后两个数为: a=%d and b=%d\n", a, b);
	system("pause");
}

练习题2第二种方法如下

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
void main()
{
	int a, b, c;
	printf("请输入要交换的两个数:\n");
	scanf("%d %d", &a, &b);
	printf("交换前的两个数为:a=%d and b=%d\n", a, b);
	a = a + b;
	b = a - b;
	a = a - b;
	printf("交换后的两个数为:a=%d and b=%d\n", a, b);
    system("pause");
}

练习题4将三个数按从大到小输出

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
void main(){
	int a, b, c, t;
	prinf("请输入三个数:\n");
	scanf("%d %d %d,&a,&b,&c");
if (a<b){
	t = a;
	a = b;
	b = t;
}
if (a<c){
	t = a;
	a = c;
	c = t;
}
if (b<c){
	t = b;
	b = c;
	c = t;
}
printf("%d %d %d\n", a, b, c);
system("pause");
	
}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页