| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1430 人关注过本帖
标题:[求助]有大侠能帮我答几道题吗?---之五
取消只看楼主 加入收藏
蓝色人鱼
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2007-3-15
收藏
得分:0 

不会运用!


2007-03-20 16:25
蓝色人鱼
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2007-3-15
收藏
得分:0 

程序是:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 400
void getResult(char *result,char *temp){
char str[MAX+10] = {0};
int i,m,n,k,y;
unsigned int j;

for(i = strlen(temp) - 1,k = 0; i >= 0; k ++,i --)
for(y = k, j = 0; j < strlen(result); y ++,j ++){
m = (temp[i] - ‘0’) * (result[j] - ‘0’);
n = y;
do{
if(str[n] == ‘\0’){
str[n] = m % 10 + ‘0’;
if(m / 10)
str[n+1] = m / 10 + ‘0’;
break;
}
m = (m + str[n] - ‘0’);
str[n] = m % 10 + ‘0’;
m = m / 10;
n ++;
}while(m);
}
if(strlen(str) >= MAX){
puts(“your should make the macro MAX bigger !”);
system(“pause”);
exit(1);
}
strcpy(result,str);
}
int main(void){
char result[MAX] = {0};
char strTemp[4];
int i;
int n;
strcpy(result,”1”);
printf(“The program will computer(n!)\nPlease enter n:”);
scanf(“%d”,&n);
for(i = 1; i <= n; i ++){
itoa(i,strTemp,10);
getResult(result,strTemp);
}
printf(“(%d!)=”,n,strlen(result));
for(i = strlen(result) - 1; i >= 0; i --)
putchar(result[i]);
putchar(‘\n’);
return 0;
}

运行结果:
The program will computer<n!>
please enter n:

求1+2+...+100的和,应该继续输入什么啊?


2007-03-20 20:40
蓝色人鱼
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2007-3-15
收藏
得分:0 
那求1*2*...*10的积,就输10回车,是吗?

2007-03-20 21:36
快速回复:[求助]有大侠能帮我答几道题吗?---之五
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024874 second(s), 8 queries.
Copyright©2004-2025, BC-CN.NET, All Rights Reserved