C语言每天练习一点

规则 1 :英文字母从 A 到 Z 排列,不区分大小写。

   如,输入: Type   输出: epTy

规则 2 :同一个英文字母的大小写同时存在时,按照输入顺序排列。

 如,输入: BabA   输出: aABb

规则 3 :非英文字母的其它字符保持原来的位置。

 如,输入: By?e   输出: Be?y

#include<stdio.h>
#include <string.h>
int main(void)
{
char str[1000]={0},temp[1000]={0};
while(gets(str))
{ int i,j,k=0;
for (i=0;i<26;i++)//对输入的字符串进行排序,从i=0开始到字符串结束,
for(j=0;j<strlen(str);j++)
{
if (str[j]‘a’+i||str[j]‘A’+i)//遍历每一位,先选出A,再选出B-Z
temp[k++]=str[j];
}
k=0;
for (i=0;i<strlen(str);i++)//对temp[k++]中的字符串进行筛选,筛选出其中为字母
{
if((str[i]>=‘a’&&str[i]<=‘z’)||(str[i]>=‘A’&&str[i]<=‘Z’))
str[i]=temp[k++];
}
printf("%s\n",str);
}
return 0;
}

每天把c语言题目简单写一下:
在这里插入图片描述

{
    
    int num,place;
printf("输入一个不多于5位数的正整数:")scanf("%d",&num);
if(num>9999)
place=5;
else if(num>999)
place=4;
else if(num>99)
place=3;
else if (num>9)
place=2;
else
place=1;
printf("位数:%d\n",place);
ten-thousand=num/10000;
thousand=(num-million*10000)/1000;
hundred=(num-million*10000-thousand*1000)/100;
ten=(num-million*10000-thousand*1000-hundred*100)/10;
indiv=(num-million*10000-thousand*1000-hundred*100-ten*10);
switch(place)
case1:
printf("\n反序数字为");
printf("%d",indiv);
break;
case2:
printf("\n反序数字为");
printf("%d,%d",indiv,ten);
break;
case3:
printf("\n反序数字为");
printf("%d,%d,%d",indiv,ten,hundred);
break;
case4:
printf("\n反序数字为");
printf("%d,%d,%d,%d",indiv,ten,hundred,thousand);
break;
case5:
printf("\n反序数字为");
printf("%d,%d,%d,%d,%d",indiv,ten,hundred,thousand,ten-thousand);
break;
}

猴子吃桃的问题:

void main()
{
    
    
int x1,x2,day;
day=10;
x2=1;
while(day>0)
{
    
    
x1=(x2+1)*2;
day--;
x2=x1;
}
}

100以内的素数:
先sqrt,再求余

for(i=1,i<100,i++)
{
    
    
k=sqr(i)
for(j=2,j<k,j++)
{
    
    
if(i%k==0)break
}
}

C语言不使用strcpy函数,实现复制字符串的功能(我记得怿星有过这道)

#include <stdio.h>
void main()
{
    
    
char s1[100],s2[100];
int i;
printf("input s1:"): 
scanf("%s",s1)for (i=1,i<strlen(s1),i++)
s2[i]=s1[i]
printf("s1:%s",s1);
}

猜你喜欢

转载自blog.csdn.net/jiaqi_ge/article/details/100077054