呵呵,有是有,估么挖地三尺能找到!
[此贴子已经被作者于2007-3-20 10:07:34编辑过]
----------------解决方案--------------------------------------------------------
#include<stdio.h>
main()
{
int i,sum=0;
for(i=1;i<=100;i++)
{
printf("%d+",i);
sum+=i;
}
printf("=%d",sum);
getch();
}
运行这个看看.......
----------------解决方案--------------------------------------------------------
不行,运行不了,江南孤峰那个可以运行,可是怎么那么长啊?
----------------解决方案--------------------------------------------------------
应该用19楼的方法嘛
等差数列求和
----------------解决方案--------------------------------------------------------
不会运用!
----------------解决方案--------------------------------------------------------
#include<stdio.h>
main()
{ int i,t=0;
for(i=1;i<=100;i++)
t+=i;
printf("t=%d",t);
}
我也是刚学,看看行不
----------------解决方案--------------------------------------------------------
程序是:
#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的和,应该继续输入什么啊?
----------------解决方案--------------------------------------------------------
100 回车
----------------解决方案--------------------------------------------------------
求什么啊,怎么都这么长,我去看看
----------------解决方案--------------------------------------------------------
到底是求1+2....+100,还是求1*2*....*100啊
求加就用这个就是了
#include <stdio.h>
main()
{int i,sum=0;
for(i=1;i<=100;i++) sum+=i;
printf("sum=%d\n",sum);
}
----------------解决方案--------------------------------------------------------