两个数组内容交换、1~100中9出现的次数、三个数从大到小输出



1、交换两个数组内容
#include<stdio.h>
#include<windows.h>
int main()
{
	int c=0, a[3] = { 1, 2, 3 }, b[3] = { 4, 5, 6 },i;
	for (i = 0; i <3; i++)
	{
		c = a[i];
		a[i] = b[i];
		b[i] = c;

		printf("%d %d\n", a[i], b[i]);
	}
	system("pause");
	return 0;
}
2、奇数分数相加,偶数分数相减
#include<stdio.h>
#include<windows.h>
int main()
{
		int i;
		double sum = 0, sum1 = 0, sum2 = 0;
		for (i = 1; i <= 50; i++)
		{
			sum1 += 1.0 / (2 * i - 1);//当i=1时,奇数为(2*i-1)
			sum2 += 1.0 / (2 * i);//2*i为偶数
		}//将式子分为偶数项相加和奇数项相加
    sum = sum1 - sum2;//偶数项减去奇数项
	printf("%f\n", sum);
	system("pause");
	return 0;
}
3、1~100中9出现的次数
#include<stdio.h>
#include<windows.h>
int main()
{
	int i, t=0,s=0;
	for (i = 1; i <= 100; i++)
	{
		if ((i % 10) == 9)//判断个位上9的数
		{
			t++;
		}
		if ((i / 10) == 9)//判断十位上9的数
		{
			s++;
		}
	}
		s += t;
	printf("%d\n",s);
	system("pause");
	return 0;
}
4、比较三个数从大到小输出
#include<stdio.h>
#include<windows.h>
int main()
{
	int a = 1, b = 2, c = 3 ,t=0;
	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");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值