3个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
int main()
{
char chNum[10] = "";
int i = 0,flag = 0;
char *p1 = NULL, *p2 = NULL;
int start = 1001;
FILE *fp = fopen("1.txt","w");
while (i < 10)
{
_itoa_s(start, chNum, 10, 10);
p1 = chNum;
p2 = p1 + strlen(p1) - 1;
flag = 1;
while (p1 < p2)
{
if (*p1 != *p2)
{
flag = 0;
break;
}
++p1, --p2;
}
if (flag)
{
++i;
fprintf(fp,"%d ", start);
printf("%d\n", start);
}
++start;
}
fclose(fp);
return 0;
}
展开全部
#include <stdio.h>
int roll(int a)
{
int i = 0, dev = 1, rol = 0, tmpa = a;
for (;a / dev >= 10 ; rol++) {
dev *= 10;
}
for (; i < rol / 2 + 1; i++) {
if (a / dev % 10 != tmpa % 10) {
return -1;
}
dev /= 10;
tmpa /= 10;
}
return 0;
}
int main()
{
int i,count = 0;
FILE *fp = fopen("1.txt", "rw");
if (fp == NULL) {
return -1;
}
for(i = 1000; ;i++) {
if (roll(i) == 0) {
fprintf(fp, "%d ", i);
count++;
}
if (count == 10) {
break;
}
}
fclose(fp);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询