第一个:统计字符个数
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, const char *argv[])
{
char str[128];
gets(str);
int coun=0;
int ccc=0;
int ppp=0;
int qit=0;
for(int i=0;i<strlen(str);i++)
{
printf("%d\n",i);
if(str[i]<='Z' && str[i]>='A')
{
coun++;
}
else if(str[i]>='a' && str[i]<='z')
{
ccc++;
}
else if(isdigit(str[i]))
{
ppp++;
}
else
{
qit++;
}
}
printf("大写母有:%d 小写字母有:%d 数字有:%d 其他字符有%d",coun,ccc,ppp,qit);
return 0;
}
运行效果:
ubuntu@ubuntu:c_1$ ./a.out
qweFFkk ppmm]] nn 555;
大写母有:2 小写字母有:11 数字有:3 其他字符有7ubuntu@ubuntu:c_1$ ./a.out
KKkkppPP uu yyyyv-0=0=0=;; 888
大写母有:4 小写字母有:11 数字有:6 其他字符有11ubuntu@ubuntu:c_1$
第二个:统计小写字符
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
char jj[]="aabbcchaaaah";
int hh[26]={0};
for(int i=0;i<strlen(jj);i++ )
{
if(jj[i]>='a'&&jj[i]<='z')
{
hh[jj[i]-97]++;
}
}
printf("a=%d",hh[0]);
return 0;
}
运行效果:
ubuntu@ubuntu:c_1$ gcc 08.c
ubuntu@ubuntu:c_1$ ./a.out
a=6ubuntu@ubuntu:c_1$
第三个:I love china
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
char hh[]="I love China";
printf("%s\n",hh);
int i=0;
int gg=7;
char jj=' ';
int k=7;
for(int qq=7;qq<=11;qq++)
{
k=qq;
while(1)
{
if(k!=i)
{
jj=hh[k];
hh[k]=hh[k-1];
hh[k-1]=jj;
}
else
{
break;
}
--k;
}
++i;
}
int III=5;
char jjjj=' ';
jjjj=hh[III];
hh[III]=hh[III+1];
hh[III+1]=jjjj;
char ptp=' ';
for(int uu=6;uu<11;uu++)
{
ptp=hh[uu];
hh[uu]=hh[uu+1];
hh[uu+1]=ptp;
}
printf("%s\n",hh);
return 0;
}
运行结果:
ubuntu@ubuntu:c_1$ ./a.out
I love China
China love I
ubuntu@ubuntu:c_1$
第四个:杨三角
#include <stdio.h>
int main(int argc, const char *argv[])
{
int arr[10][10]={0};
for(int i=0;i<10;i++)
{
arr[i][0]=1;
}
for(int u=1;u<10;u++)
{
for(int r=1;r<10;r++)
{
arr[u][r]=arr[u-1][r]+arr[u-1][r-1];
}
}
for(int yy=0;yy<10;yy++)
{
for(int ww=0;ww<=yy;ww++)
{
printf("%d\t",arr[yy][ww]);
}
printf("\n");
}
return 0;
}
运行结果:
ubuntu@ubuntu:c_1$ gcc 06.c
ubuntu@ubuntu:c_1$ ./a.out
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1