2.输入一字符串,放到数组里,删除其中的空格
3.输出1 1 2 3 5 8 13 21.......Fibonacci数列前20项
4.键盘输入一个字符串,判断其是否回文
2.输入一字符串,放到数组里,删除其中的空格
3.输出1 1 2 3 5 8 13 21.......Fibonacci数列前20项
4.键盘输入一个字符串,判断其是否回文
#include<stdio.h>
#include<string.h>
1.
void main( )
{
int i, j, temp;
int date[20]={0};
printf( "请输入要排序的数:\n" );
for ( i=0; i < 20; i++ )
scanf ( "%d",&date[i] );
for ( i=0; i<20; i++ )
for ( j=i+1; j<20; j++ )
if ( date[i] > date[j] )
{
temp=date[i];
date[i]=date[j];
date[j]=temp;
}
for ( i=0;i<20;i++ )
printf ( "%d ",date[i]);
printf("\n");
}
2.
void main( )
{
int i=0,j=0;
char str1[100]={0},str2[100]={0};
printf ( "请输入字符串:\n" );
gets(str1);
while(str1[i]!='\0')
{if(str1[i] != ' ')
{
str2[j]=str1[i];
j++;
}
i++;
}
str2[j]='\0';
puts(str2);
printf("\n");
}
3.
void main()
{
int i=0;
int fib[20]={0};
fib[0]=1;
fib[1]=1;
for (i=2;i<20;i++)
fib[i]=fib[i-2]+fib[i-1];
for (i=0;i<20;i++)
printf( "%d ",*(fib+i) );
printf("\n");
}
4.
void main()
{
int i,j=0,leap=10;
char str[100]={0};
printf( "enter str:\n");
gets(str);
i=strlen(str)-1;
for ( leap=1;i>=j;i--,j++)
{if(str[i]==str[j])
leap=1;
else
leap=0;
if(leap==0)break;
}
if(leap==1)
printf("%s is huiwen\n",str);
else
printf("%s is not huiwen\n",str);
}