第一题
运用数组进行逆序处理
#include <stdio.h>
int main()
{
int a[100];
int i;
int count=0;
int z;
int y;
int temp;
int x;
scanf("%d",&x);
if (x < 0 || (x % 10 == 0 && x != 0))
{
printf("false");
}
if (x == 0)
{
printf("true");;
}
temp = x;
while (temp >= 10)
{
temp = temp / 10;
count++;
}
for ( i = 0; i <= count ; i++)
{
z = x / 10;
y = x % 10;
a[i] = y;
if (z < 10)
{
a[i + 1] = z;
break;
}
if (z >= 10)
{
x = z;
}
}
for ( i = 0; i <= count; i++,count--)
{
if (a[i] == a[count])
{
printf("true");
}
else
{
printf("false");
}
}
return 0;
}
问题
1 运行结果有两个,不知道哪里出错
2 上面代码中a[count]不晓得是啥
第二题
运用逆序
#include<stdio.h>
int main()
{
int x;
int a;
int b=0;
scanf("%d",&x);
while(x>0||x<0 ){
a=x%10;
x/=10;
b=b*10+a;
}
printf("%d",b);
return 0;}
第三题
第一列和每一行最后一位数都为1,分为前2行和其他,中间除第一个和最后一个外,其他的都为上面一个及上面一个左侧之和
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
int i,j,a[n][n];
for (i=0;i<n;i++){
a[i][i]=1;
a[i][0]=1;
}
for(i=2;i<n;i++)
for(j=1;j<=i-1;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j];
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
printf("%6d",a[i][j]);
printf("\n");
}
printf("\n");
return 0;
}