C 语言教程 在线

1785c-exercise-example35

参考方法:

#include <stdio.h>
#include <string.h>
int main()
{
    char s[128] = {0}, s1[128] = {0};
    int i, j = 0;
    printf("请输入字符串:");
    gets(s);
    for (i = strlen(s) - 1; i >= 0; i--)
    {
        s1[j++] = s[i];
    }
    puts(s);
    puts(s1);
    return 0;
}

1784c-exercise-example35

参考方法:

#include<stdio.h>
#include<string.h>

void reverse(char *str)
{
    int len;
    char tmp;
    char *begin,*end;
    len=strlen(str); //获取字符串长度]
    begin=str;       //指针begin指向字符串首地址
    end=str+len-1;     //指针end指向字符串尾地址
    while(begin<end)
    {
        tmp=*begin;
        *begin=*end;
        *end=tmp;
        begin++;
        end--;
    }
}

int main()
{
    char string[]="www.facesho.com";
    reverse(string);
    puts(string);
    return 0;
}

1783c-exercise-example35

参考解法:

#include <stdio.h>
#include<string.h>

int main()
{
    char c[1000];
    fgets(c, (sizeof c / sizeof c[0]), stdin);
    int d=strlen(c);
    //printf("%d\n",d);
    char a[1000];
    int j=0;
    for(int i=d-1;i>=0;i--)
    {
        a[i]=c[j];
        j++;
    }
    puts(a);
}

1782c-exercise-example34

参考方法:

#include <stdio.h>
void Print(int n){
    if(n){
        printf("hello world\n");
        Print(n-1);
    }
}

int main(){
    int n;
    printf("打印多少次:");
    scanf("%d",&n);
    Print(n);
    return 0;
}

1781c-exercise-example33

参考方法:

#include<stdio.h>
#include<math.h>

int main()
{
    int i, m, n=0;
    printf("输入一个大于1的自然数:\n");
    scanf("%d", &m);
    for(i=2; i<= floor(sqrt(m)+0.5); i++)
    {
        if (m%i == 0)
        {
            n += 1;
        }
    }

    if (n == 0)
    {
        printf("是质数\n");
    }
    else
    {
        printf("不是质数\n");
    }
    return 0;
}