回文函数c语言程序 回文数c程序编写

C语言“回文”程序代码

首先我对你的 "并且当输入的字符串第一个字符为#时,输入为空时,不输出。" 这句话比较费解, 不明白你的意思!

创新互联建站专注于企业营销型网站建设、网站重做改版、玛曲网站定制设计、自适应品牌网站建设、H5页面制作商城网站开发、集团公司官网建设、成都外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为玛曲等各大城市提供网站开发制作服务。

你把这说清楚了我再补充回答你~

我写了个参考代码给你参考, 首先是输入你要判断的字符串的个数, 然后再依次输入所有的字符串, 最后判断输入的所有字符串是否是"回文"! 因为不理解你那句话, 所以暂时没做什么空和什么"#"处理.

详细c代码:

#include stdio.h

#include string.h

#define STR_LEN 128

#define STR_NUM 64

int main()

{

int i = 0, j = 0, n = 0;

int len = 0;

char *start = NULL;

char *end = NULL;

char str[STR_NUM][STR_LEN] = {0};

printf("Please input the number of string: \n");

scanf("%d", n);

printf("Please input all the string: \n");

for (i = 0; i n; i++)

{

scanf("%s", str[i]);

}

for (j = 0; j n; j++)

{

start = str[j];

len = strlen(str[j]);

end = str[j] + len - 1;

while (start - end = 0)

{

if (*start++ != *end--)

{

break;

}

}

if (start end)

{

printf("yes\n");

}

else

{

printf("no\n");

}

}

return 0;

}

例子,运行后:

Please input the number of string:

4

Please input all the string:

aba

112ds

madam

xyzyx

yes

no

yes

yes

Press any key to continue

补充回答:

大概明白你的意思,我会把例子贴上, 若不符合你的要求我再帮修改!

详细代码如下:

#include stdio.h

#include string.h

#define STR_LEN 128

#define STR_NUM 64

int main()

{

int i = 0;

int len = 0;

int str_count = 0;

char *start = NULL;

char *end = NULL;

char str[STR_NUM][STR_LEN] = {0};

printf("Please input all the string: \n");

while (1)

{

scanf("%s", str[str_count]);

if (str[str_count][0] == '#')

{

break;

}

else

{

str_count++;

continue;

}

}

for (i = 0; i str_count; i++)

{

start = str[i];

len = strlen(str[i]);

end = str[i] + len - 1;

while (start - end = 0)

{

if (*start++ != *end--)

{

break;

}

}

if (start end)

{

printf("yes\n");

}

else

{

printf("no\n");

}

}

return 0;

}

运行实例1:

Please input all the string:

xyzyx

adghf

#

yes

no

Press any key to continue

运行实例2:

Please input all the string:

1232ss

sakljfkla

333dafs

aba

ee3

xyzyx

dfj222

madam

111$111

slsl33

#

no

no

no

yes

no

yes

no

yes

yes

no

Press any key to continue

c语言回文补充程序?

#include stdio.h

#include string.h

#include ctype.h

int ispalindrome(char *str) {

int s=0,e=strlen(str)-1,m=(s+e)/2;

while(s=mstr[s]==str[e])

{

s++;

e--;

}

if(sm)

return 1;

return 0;

}

int main(void) {

char buffer[1024];

gets(buffer);

printf("[%s] is ", buffer);

if (ispalindrome(buffer)) puts("a palindrome");

else puts("not a palindrome");

return 0;

}

c语言关于回文数的程序,找到了,不太懂

你这代码的运行结果是:

a.exe

11      101     111

这明显有问题啊,11~999,怎么可能就这三个,下面是我写的回文数的程序,供你参考下吧

#include stdio.h

#define N 1000  //定义符号常量

//判断是否为回文数的函数

int isHuiwenNumber(int n)

{

int sum,tmp;

tmp=n;

sum=0;

while(n)  //从低位到高位分解n的每位的数字,然后依次相加

{

sum=sum*10+n%10;

n/=10;

}

if(tmp == sum) //如果重新每位求和的值等于原值,则该数为完数,返回1,否则返回0

return 1;

else

return 0;

}

int main()

{

int i,count;

for(i=11,count=0;iN;i++)

{

if(isHuiwenNumber(i))  //调用函数,如果条件为真,执行if语句体

{

printf("%-6d",i);   //输出回文数

count++;

if(count % 20 == 0) //每行输出20个后便换行

printf("\n");

}

}

return 0;

}

用C语言编写程序,判断一个数是否为回文数。

1、首先打开vc6.0,新建一个控制台项目。

2、添加头文件。

3、添加main主函数。

4、定义6个long型变量。

5、使用scanf给input赋值。

6、分解个位、百位、千位、万位。

7、使用if判断。

8、运行程序,看看结果。

c语言程序设计编求回文数的函数

#includestdio.h

int main(){

int m[16], n, i, t, count=0;

long unsigned a, k;

printf("No.    number     it's square(palindrome)\n");

for( n=1; n256; n++ )  /*穷举n的取值范围*/

{

k=0; t=1; a=n*n;  /*计算n的平方*/

for( i=0; a!=0; i++ )  /*从低到高分解数a的每一位存于数组m[1]~m[16]*/

{

m[i] = a % 10;

a /= 10;

}

for(; i0; i--)

{

k += m[i-1] * t;  /*t记录某一位置对应的权值 */

t *= 10;}

if(k == n*n)printf("%2d%10d%10d\n", ++count, n, n*n);

}

return 0;

}

扩展资料:

C语言在编写的时候需要说明的是:

1、一个C语言源程序可以由一个或多个源文件组成。

2、每个源文件可由一个或多个函数组成。

3、一个源程序不论由多少个文件组成,都有一个且只能有一个main函数,即主函数。是整个程序的入口。

4、源程序中可以有预处理命令(包括include 命令,ifdef、ifndef命令、define命令),预处理命令通常应放在源文件或源程序的最前面。

5、每一个说明,每一个语句都必须以分号结尾。但预处理命令,函数头和花括号“}”之后不能加分号。(结构体、联合体、枚举型的声明的“}”后要加“ ;”)。

6、标识符,关键字之间必须至少加一个空格以示间隔。若已有明显的间隔符,也可不再加空格来间隔。

参考资料:

百度百科-回文数

C语言编回文数

#include stdio.h

#include stdlib.h

int huiwen(char *str) /* 回文子函数 */

{

int len=strlen(str);

int i=0;

for(i=0; ilen/2; i++) {

if(*(str+i) != *(str+len-1-i)) return 1;

}

return 0;

}

int main()

{

int i=0;

char str[5];

int hw6[10000] = {0};

int cnt=0;

int max=0;

printf("所有回文数:\n");

for(i=9999; i=100; i--) {

memset(str, 0, 5);

sprintf(str, "%d", i);

if(huiwen(str) == 0) {

printf("%d\n", i); /* 这里把所有回文数打印出来 */

if(i % 6 == 0) {

hw6[cnt++] = i; /* 记录下被6整除的回文数 */

if(max == 0)

max = i; /* 最大被6整除的回文数,只会被执行一次 */

}

}

}

printf("能被6整除的回文数:\n");

for(i=0; icnt; i++) {

printf("%d\n", hw6[i]);

}

printf("最大回文数: %d\n",max);

}


名称栏目:回文函数c语言程序 回文数c程序编写
本文地址:http://lszwz.com/article/doocgod.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款