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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include
// 一、统计个数
#include<stdio.h>
int main()
{
char ch[10];
gets(ch);
int big=0, small=0, num=0, blank=0, other=0;
int i;
for(i = 0; i < 10 ; i ++)
{
if ( ch [ i ] > = 'a' && ch[i] < = 'z')
small ++;
else if(ch[i] >='A' && ch[i] < = 'Z')
big ++;
else if(ch[i] == ' ')
blank ++;
else if(ch[i] >= '0' && ch[i] < = '9')
num ++;
else
other ++;
}
printf("大写字母:%d\n",big);
printf("小写字母:%d\n",small);
printf("数字%d\n",num);
printf("空格%d\n",blank);
printf("其他字符:%d\n",other);
}
#include <stdio.h>
//二、判断素数
int main() {
int n;
printf("请输入一个1-100之间的整数: \n");
scanf("%d", &n);
int m = 0;
for (int i = 2; i < n ; i ++ ) {
if ( n % i = = 0 ) {
m ++;
}
}
if ( m = = 0 ) {
printf ("% d 是素数 \n", n );
} else {
printf ("% d 不是素数 \n", n );
}
return 0 ;
}
三、求斐波那契数列
#include<stdio.h>
int fib ( int n )
{
if ( n = =1||n==2)
return 1 ;
else
return fib ( n-1 )+ fib ( n-2 );
}
int main ()
{
int n , i ;
scanf ("% d ",& n );
printf ("前 n 项斐波那契数列为: \n");
for ( i = 1;i<=n;i++)
printf ("% d ", fib ( i ));
}
//四、输出菱形图形
#include<stdio.h>
#include<math.h>
int main ()
{
int n , i , j , k , m ;
printf ("请输入一个整数: \n");
scanf ("% d ", & n );
printf ("图形为");
m = 2 * n - 1 ;
for ( i = 1; i <= n ; i ++)
{
for ( j = 1; j <= abs ( i - n ); j ++)
printf (" ");
for ( k = j ; k <= m - abs ( i - n ); k ++)
printf ("*");
printf (" \n");
}
for ( i = n - 1 ; i > = 1; i --)
{
for(j = 1; j < = abs(i - n); j ++)
printf(" ");
for(k = j ; k < = m - abs(i - n); k ++)
printf("*");
printf("\n");
}
return 0;
}