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");
}
}

#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;

//这里!

s *= (-1);

n+=2;

epselon=fabs(t);

}while(epselon>=1e-6);

printf("pi=%8.6f\n",4*pi);

}
(2)
#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);

//这里!

if((fp=fopen("test.txt","r"))==NULL){

printf("Can't open this file.\n");

exit(0);

}

fgets(str,strlen(str)+1,fp);

printf("%s\n",str);

fclose(fp);

}
(3)
#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++)

//这里!

a[i][j] = 1;

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-12-01
太长了 ~眼花~
第2个回答  2007-12-02
41.s=-s;

42.if((fp=fopen("test.txt","r"))!=NULL)

43.a[i][j]=1;

我全部在TC2.0上做了一遍
第3个回答  2007-12-03
诶。!拿不走。`!!!!!!!!!!!
遗憾。`!
第4个回答  2007-12-07
41.
#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;
_____s=-s;_________________
n+=2;
epselon=fabs(t);
}while(epselon>=1e-6);
printf("pi=%8.6f\n",4*pi);
}

42.
#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);
___if((fp=fopen("test.txt","r"))!=NULL)_____________________
fgets(str,strlen(str)+1,fp);
printf("%s\n",str);
fclose(fp);
}

43.
#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++)
_____a[i][j]=1;______________
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");
}
}
第5个回答  2007-12-13
身为大一新生的我对这个还是菜鸟,只能看别人抢分啦
相似回答
大家正在搜