Problem B: 指针:调用自定义排序函数sort,对输入的n个数进行从小到大输出。

Problem B: 指针:调用自定义排序函数sort,对输入的n个数进行从小到大输出。

Description

自定义函数sort(int *p, int n),功能是对n个数排序。在main函数中,调用它,对输入的任意个数排序。

Input

多组测试数据,先输入n(n<100),再输入n个任意整数

Output

输出从小到大排列后的数组

Sample Input

5
9 4 3 2 1
6
34 23 12 78 -20 0

Sample Output

1 2 3 4 9
-20 0 12 23 34 78

#include<stdio.h>
int main()
{
	int sort(int *p,int n)int n,a[100],i;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        sort(a,n);
        for(i=0;i<n-1;i++)
        printf("%d ",a[i]);
        printf("%d",a[n-1]);
        printf("\n");
    }
    return 0;
} 
int sort(int *p,int n)
{
    int i,j,temp;
    for(i=0;i<n-1;i++)
    for(j=i;j<n;j++)
    if(p[i]>p[j])
    {
        temp=p[i];
        p[i]=p[j];
        p[j]=temp;
    }
}

暂不支持中文模型,以下为英文回答: To solve this problem, we need to first define what a palindrome prime is. A palindrome prime is a prime number that is also a palindrome number, which means that it reads the same from left to right as from right to left. Now, we can start by generating all prime numbers up to a certain limit, and then checking which of these primes are also palindrome numbers. Here is a Python code that does this: ```python def is_prime(n): if n < 2: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def is_palindrome(n): return str(n) == str(n)[::-1] n = int(input()) count = 0 i = 2 while count < n: if is_prime(i) and is_palindrome(i): print(i, end=" ") count += 1 i += 1 ``` In this code, the `is_prime` function checks whether a given number is prime or not using a simple trial division algorithm. The `is_palindrome` function checks whether a given number is a palindrome number by converting it to a string and comparing it with its reversed string. The main loop then generates prime numbers starting from 2, and checks whether each number is a palindrome prime. Once `n` palindrome primes have been found, the loop stops and the program prints the list of palindrome primes in ascending order. Note that this code may not be very efficient for large values of `n`, since it generates all prime numbers up to `n` and checks each of them for palindrome-ness. A more efficient approach would be to use a sieve algorithm to generate only the first `n` primes, and then check each of these primes for palindrome-ness.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值