每日一题(3)

 第一题、闰年展示

 题解:

#include <iostream>
using namespace std;
//闰年
//能被4整除,但不能被100整除
//能被400整除
int main()
{
    int x = 0, y = 0, num = 0;
    int arr[1000] = { 0 };
    cout << "请输入两个年份:" << endl;
    cin >> x >> y;
    for (int i = x; i <= y; i++)
    {
        if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
        {
            arr[num] = i;
            num++;
        }
    }
    cout << num << endl;
    for (int i = 0; i < num; i++)
    {
        cout << arr[i] << " ";
        //if ((i + 1) % 10 == 0)//每行输出10个数
        //{
        //    cout << endl;
        //}
    }
    system("pause");
    return 0;
}


第二题:质数筛

 题解:

01、

#include <iostream>
using namespace std;
bool func(int n)
{
	if (n == 1||n == 0 )
	{
		return false;
	}
	for (int i = 2; i < n; i++)
	{
		if (n % i == 0)
		{
			return false;
		}
	}
	return true;
}
int main()
{
	int n = 0, mark;
	int arr[100];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	for (int i = 0; i < n; i++)
	{
		if (func(arr[i]))
		{
			cout << arr[i] << endl;;
		}
	}
	system("pause");
	return 0;
}

 02、

#include <iostream>
using namespace std;
int main()
{
	int n = 0, mark;
	int arr[100];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	for (int i = 0; i < n; i++)
	{
		int mark=0;
		for (int j = 2; j < arr[i]; j++)
		{
			if (arr[i] % j == 0)
			{
				mark = 1;
				break;
			}
		}
		if (mark == 0)
		{
			cout << arr[i]<<" ";
		}
	}
	system("pause");
	return 0;
}

三、距离函数

题解:

#include <iostream>
#include<cmath>
#include<iomanip>
using namespace std;
double dis(double x1, double y1, double x2, double y2)
{
	double ans;
	ans = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	ans = sqrt(ans);
	return ans;
}
int main()
{
	double x[3] = { 0 }, y[3] = { 0 }, ab, ac, bc, C;
	cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];
	ab=dis(x[0], y[0], x[1], y[1]);
	ac=dis(x[0], y[0], x[2], y[2]);
	bc=dis(x[1], y[1], x[2], y[2]);
	C = ab + ac + bc;
	printf("%.2f", C);
	system("pause");
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值