26-----30

26.#include <stdio.h>
#include <math.h>
int prime(int n)
{
    int i;
    long k;
    k = sqrt(n) + 1;
    for (i = 2; i <= k; i++)
        if (n%i == 0)
            return 0;
        return 1;
}
int main()
{
    int mp, n = 0, i;
    printf("MersennePrime:\n");
    for (i = 2; i <= 20; i++)
    {
        mp = pow(2, i) - 1;
    if (prime(mp))
    {
        n++;
        printf("M(%d)=%d", i, mp);
               printf("\n");
    }
    }
    printf("thenumber of Mersenne Prime less than 20 is:%d\n", n);
    return 0;
}

27.

#include<stdio.h>
int main(){

char a,b,c;
        for(a = 'x'; a <= 'z'; a++) {
            for(b = 'x'; b <= 'z'; b++) {
                if(a != b) {   //避免参赛队员重复比赛
                    for(c = 'x'; c <= 'z'; c++) {
                        if(a != c && b != c) {      //避免参赛队员重复比赛
                            if(a != 'x' && c != 'x' && c != 'z') {   //根据题意判断
                                printf("a和%c,b和%c,c和%c进行比赛",a,b,c);
                            }
                        }
                    }
                }
            }
        }
}
28.#include<stdio.h> 
he(int n,int m) 
{     
    int sum=0;
    if(n==m)     
        return(n);     
    else     
        return(n+he(n+1,m)); 

main() 
{     
    int n,m;     
    scanf("%d%d",&n,&m);     
    printf("%d",he(n,m)); 
}

29.

#include "stdafx.h"
#include<iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
int a,b,c,t;
cin>>a>>b>>c;
int *p1,*p2,*p3;


p1=&a;        //将变量a的地址存放到指针变量p1中
p2=&b;
p3=&c;


if(*p1>*p2)
{
t=*p1;
*p1=*p2;
*p2=t;
}


if(*p1>*p3)
{
t=*p1;
*p1=*p3;
*p3=t;

if(*p2>*p3)
{
t=*p2;
*p2=*p3;
*p3=t;
}


cout<<*p1<<" "<<*p2<<" "<<*p3<<endl;


return 0;
}
30.
#include <stdio.h>
#include <string.h>

int main()
{
    void sort(char *p_s1, char *p_s2);
    char str1[100], str2[100], str3[100];
    char *p_s1=str1,*p_s2=str2,*p_s3=str3;
    printf("请随意输入三个字符串:\n");
    gets(p_s1); 
    gets(p_s2); 
    gets(p_s3); 
    sort(p_s1, p_s2);
    sort(p_s1, p_s3);
    sort(p_s2, p_s3);
    printf("按照由小到大的顺序输出如下:\n%s\t%s\t%s\t", p_s1, p_s2, p_s3); 
    return 0;

void sort(char *p_s1, char *p_s2)
{
    char temp[100]; 
    if(strcmp(p_s1,p_s2)>0){
        strcpy(temp, p_s1);
        strcpy(p_s1, p_s2);
        strcpy(p_s2, temp);    
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值