You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
882 B
63 lines
882 B
//字符类型判断
|
|
#include <stdio.h>
|
|
void count(char *s, int *digit, int *letter, int *other, int *lower, int *k)
|
|
{
|
|
int i;
|
|
for(i=0;i<10;i++)
|
|
{
|
|
if(s[i]>='a'&&s[i]<='z')
|
|
(*letter)++;
|
|
else if(s[i]>='A'&&s[i]<='Z')
|
|
(*lower)++;
|
|
else if(s[i]>'0'&&s[i]<'9')
|
|
(*digit)++;
|
|
else if(s[i]==' ')
|
|
(*k)++;
|
|
else
|
|
(*other)++;
|
|
}
|
|
|
|
}
|
|
|
|
int main()
|
|
{
|
|
int x=0,y=0,z=0,a=0,b=0;
|
|
char ch[80];
|
|
printf("Enter a string:");
|
|
gets(ch);
|
|
count(ch,&x,&y,&z,&a,&b);
|
|
printf("小写字母有:%d个,大写字母有:%d个,数字有: %d个,空格有: %d个,其它符号有:%d个\n",x,y,z);
|
|
}
|
|
|
|
//斐波那契数列
|
|
#include <stdio.h>
|
|
void fib(int n)
|
|
{
|
|
int i,a,b,c;
|
|
for(i=0;i<n;i++)
|
|
{
|
|
if(i>1)
|
|
{
|
|
c=a+b;
|
|
printf("%d ",c);
|
|
a=b;
|
|
b=c;
|
|
}
|
|
else
|
|
{
|
|
a=1;
|
|
b=1;
|
|
printf("1 ");
|
|
}
|
|
}
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
int i;
|
|
scanf("%d",&i);
|
|
fib(i);
|
|
return 1;
|
|
}
|
|
|