C语言的题 问答题 !!速度!!!分很高!!

41、采用下面的公式编程求π,要求计算到最后一项的值小于10-6为止。

#include <stdio.h>
#include <math.h>
void main()
{double n=1,t=0,pi=0.0,s=1.0,epselon;
do
{t=s/n;
pi+=t;
____________________________________________
n+=2;
epselon=fabs(t);
}while(epselon>=1e-6);
printf("pi=%8.6f\n",4*pi);
}
42、从键盘输入一个字符串,将其中的小写字母全部转换成大写字母,然后输出到一个磁盘文件“test.txt”中保存。输入的字符串以“!”结束。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{FILE *fp;
char str[100];
int i=0;
if((fp=fopen("test.txt","w"))==NULL)
{printf("Can't open this file.\n");
exit(0);
}
printf("Input a string:\n");
gets(str);
while(str[i]!='!')
{if(str[i]>='a'&&str[i]<='z')
str[i]=str[i]-32;
fputc(str[i],fp);
i++;
}
fclose(fp);
_______________________________________________________________
fgets(str,strlen(str)+1,fp);
printf("%s\n",str);
fclose(fp);
}
43、将一个10×10的矩阵对角线元素置0,其余元素置1。
#include <stdio.h>
#define N 10
void main()
{int a[N][N],i,j;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
_______________________________________________________
for(i=0;i<N;i++)
{a[i][i]=0;
a[i][N-i-1]=0;
}
for(i=0;i<N;i++)
{for(j=0;j<N;j++)
printf("%2d",a[i][j]);
printf("\n");
}
}

第1个回答  2007-11-27
#include "stdafx.h"
#include "stdio.h"
#include "iostream.h"

int main(int argc, char* argv[])
{
int carry,n,j;
int a[2000];
int digit=1;
int temp,i;
cout<<"please enter n:"<<endl;
cin>>n;
a[0]=1;
for(i=2; i<=n; i++)
{
for(carry=0,j=1; j<=digit; ++j)
{
temp=a[j-1]*i+carry;
a[j-1]=temp%10;
carry=temp/10;
}
while(carry)
{
//digit++;
a[++digit-1]=carry%10;
carry/=10;
}
}
cout<<"the result is:"<<endl;
for(int k=digit; k>=1; --k)
cout<<a[k-1];
cout<<endl;
return 0;
}
第2个回答  2007-11-27
43.a[i][j]=1
其他的不会,我也混2分
第3个回答  2007-11-27
晕,哥们大二时这个题对我来说实在太轻松了,不过现在……呵呵……
第4个回答  2007-11-27
43.a[i][j]=1
其他的不会
相似回答
大家正在搜