无锡新安发展规划:谁能帮帮我啊?急!!!!!

来源:百度文库 编辑:高校问答 时间:2024/05/03 12:26:09
谁能帮我用C++编下面两个 程序啊?
1.编写一个程序,计算任一输入的正整数的各位数字之和。
2.编写一个程序,判断一个字符是否为“回文”(顺读和倒读都一样的字符串称“回文”)。

1.
/*
求整数a各位数之和
*/
int sum(int a)
{
int t=0;
while(a)
{
t+=a%10;
a=a/10;
}
return t;
}

2.判断回文
#include <string.h>
#include <ctype.h>
/*
To test if a string is a palindrome
return 1 is s is a palindrome
otherwise return 0
*/
int palind(const char *s)
{
int l;
int r;

if (s == NULL) return 0;

l = 0;
r = strlen(s);

while(l<r)
{
while (!isalpha(s[l])) l++;
while (!isalpha(s[r])) r--;
if (tolower(s[l])!=tolower(s[r]))
{
return 0;
}
l++;
r--;
}
return 1;
}

#include <stdio.h>

int main()
{
return 0;
}

int jiajia(int n)
{
int sum=0;

do
{
sum += n%10;
n = n/10;
}while (n/10 != 0)
printf("%d", sum);
}

void huiwenshu()
{
int i,j,a,b,n=1;
b=0;
scanf("%d",&s);
do
{
s=float(s)/10;
n++;
}
while (s>=0)
for (i=1;i<=n;i++)
{
a=s%10;
s=s/10;
b=b+a;
}
printf("%d",b);
}

楼上的不知道C++也来回答,勇气可嘉~~~
以前学过,差不多忘光了,但能在学多C++教材啊练习啊中找到相关的吧。