#include <stdio.h>
#include <stdlib.h>
void test()
{
int i=0;
int sum=1;
for(i=9;i>0;i--)
{
sum=(sum+1)*2;
}
printf( "the total=%d\n",sum);
}
int main()
{
test();
system( "pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void test()
{
int i=0;
float sum=0;
for(;i<100;i++)
{
sum+=(pow(-1.0,i))/(i+1);
}
printf( "sum=%f\n",sum);
}
int main()
{
test();
system( "pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
void test()
{
int tmp=1;
int sum=0;
for(int i=1;i<=20;i++)
{
tmp=i*tmp;
sum+=tmp;
}
printf( "sum=%d\n",sum);
}
int main()
{
test();
system( "pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
void test()
{
int m=0;
printf( "Please input the figure:" );
scanf( "%d",&m);
int n=0; //反转后的数
int tmp=m;
while(tmp)
{
n=n*10+tmp%10;
tmp/=10;
}
if(n==m)
printf( "Yes\n");
else
printf( "No\n");
}
int main()
{
test();
system( "pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void test()
{
char* str="12bn21" ;
char* start=str;
char* end=str+strlen(str)-1; //注意此处end的定义
while(start<end)
{
if(*start==*end)
{
start++;
end--;
}
else
{
printf( "%s\n",str);
printf( "No\n");
return;
}
}
printf( "%s\n",str);
printf( "Yes\n");
}
int main()
{
test();
system( "pause");
return 0;
}
改为char* str="123abnba321" ; 结果为
sizeof:运算符,计算字节数
strlen:函数,计算字符串长度
转载于:https://blog.51cto.com/ljy789/1828906