回数问题见下面程序,下次还是把代码贴上,对着图片全打代码还是耗时间呢
int hws(long n)
{
long x=n,t=0,i;
if(x==1000)
return 0;
else
{
t=x%10;//个位
i=(x/100)%10;//百位
if(i!=0&&t==i)//百位不为零且百位与个位相等,即为回数
{
return 1;
}
else
return 0;
}
}
第一题:
#include <stdio.h>
int hws(long n)
{
long x = n, t = 0, i;
/**********Program**********/
while (x){
i = x % 10;
t = t * 10 + i;
x /= 10;
}
return t == n;
/**********End*************/
}
int main()
{
long i;
int k = 0;
int hws(long n);
for (i = 100;i <= 1000; i++)
if (hws(i))
k++;
printf("100到1000之间的回文数的个数为:%d\n", k);
return 0;
}
第二题:
#include <stdio.h>
void main()
{
char s1[20]="xy",s2[]="ab12DFc3G",*t1=s1,*t2=s2;
while (*t1 != '\0')
/***********SPACE**********/
t1++; //【?】
while (*t2 != '\0')
{
if (*t2 >= '0' && *t2 <= '9')
{
/***********SPACE**********/
*t1 = *t2; //【?】
t1++;
}
t2++;
}
/***********SPACE**********/
*t1='\0'; //【?】
puts(s1);
}