c语言编程题,请高手帮忙做一下,拜谢,急急急急……

运行环境VC++6.0

1、根据圆周率公式π=(1-1/3+1/5-1/7+……+1/(4n-3)-1/(4n-1))*4
计算圆周率,自定义函数f(n),根据输入的n值计算出对应的π值,并输出
2、学生信息处理程序,从键盘输入三名学生的姓名,数学成绩,语文成绩,英语成绩,计算出各自的总分,按照总分从低到高的顺序输出结果
姓名 数学成绩 语文成绩 英语成绩 总分
3、大数运算 ,设计算法实现100一下的阶乘精确值!要加注释!

1.
#include <stdio.h>

double funcPi(int);

int main(void)
{
int arg;
printf("Input the argument: ");
//
// 无异常输入
//
while (!scanf("%d", &arg))
{
printf("Check your input and retry: ");
while (getchar()!='\n')
{
continue;
}
}
while (getchar()!='\n')
{
continue;
}
//
// 调用函数,输出结果
//
printf("%lf", funcPi(arg));

return 0;
}
//
// 函数定义,不用太多解释了吧?一个循环解决正数值的累加,另一个是负数值的累加。
//
double funcPi( int n )
{
double back = 0.0;
int count;

for (count = 1; count <= 4*n-1; count+=4)
{
back += (double)1/count;
}
for (count = 3; count <= 4*n-1; count+=4)
{
back -= (double)1/count;
}

return 4*back;
}

2.
#include <stdio.h>
#define LEN 3
#define N 30
//
// 结构定义
//
typedef struct stu
{
char name[N];
float scrOfMth;
float scrOfChn;
float scrOfEng;
float scrOfAll;
}Stu;

void swap( Stu *a, Stu *b );

int main(void)
{
Stu table[LEN]; // 申请一个长度为3的结构数组来存放数据
int count = 0;
char *p[5] = {"姓名","数学成绩","语文成绩","英语成绩","总分"};
//
// 输入数据并计算总分,基本可以实现无异常输入,名字数组长度30,有越界可能
//
for(count = 0; count < LEN; count++)
{
printf("Input student%d's name: ", (count+1));
gets(table[count].name);

printf("Input the score of Math: ");
while(!scanf("%f", &table[count].scrOfMth))
{
printf("Check your input and retry.\n");
while(getchar()!='\n')
{
continue;
}
}
while(getchar()!='\n')
{
continue;
}

printf("Input the score of Chinese: ");
while(!scanf("%f", &table[count].scrOfChn))
{
printf("Check your input and retry.\n");
while(getchar()!='\n')
{
continue;
}
}
while(getchar()!='\n')
{
continue;
}

printf("Input the score of English: ");
while(!scanf("%f", &table[count].scrOfEng))
{
printf("Check your input and retry.\n");
while(getchar()!='\n')
{
continue;
}
}
while(getchar()!='\n')
{
continue;
}

table[count].scrOfAll = table[count].scrOfMth + table[count].scrOfChn
+ table[count].scrOfEng;
}
//
// 因为数组长度只有3,所以用3个if就可以实现排序,没有用排序算法
//
if( table[0].scrOfAll > table[1].scrOfAll )
{
swap(table, table+1);
}

if( table[1].scrOfAll > table[2].scrOfAll )
{
swap(table+1, table+2);
}

if( table[0].scrOfAll > table[1].scrOfAll )
{
swap(table, table+1);
}
//
// 打印表头,然后输出列表
//
for(count = 0; count < 5; count++)
{
printf("%s\t", p[count]);
}
printf("\n");
for(count = 0; count < LEN; count++)
{
printf("%s\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\n", table[count].name, table[count].scrOfMth, table[count].scrOfChn, table[count].scrOfEng, table[count].scrOfAll);
}

return 0;
}
//
// 函数swap,交换两个结构的数据
//
void swap( Stu *a, Stu *b )
{
Stu temp;

temp = *a;
*a = *b;
*b = temp;
}

3.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define MAX 10000000;

void factory(int *, int, int);

int main(void)
{
int arg = 0; // 阶乘底数
double temp = 0.0; // 临时存储器
int length = 0; // 内存长度
int *pointer = NULL; // 指针
int count = 0; // 计数器

printf("Input the argument(integer): ");
while (!scanf("%d", &arg))
{
printf("Check your input and retry: ");
while (getchar()!='\n')
{
continue;
}
}
while (getchar()!='\n')
{
continue;
}
//
// 计算需要多大的数组(足够,但可能多)
//
for (count = 1; count <= arg; count++)
{
temp += log10((double)arg);
}

length = (int)temp/7 + 1;

pointer = (int *) malloc( length * sizeof(int) );
//
// 调用函数计算阶乘
//
factory( pointer, length, arg );
//
// 找到最后一个不等于0的元素,从该元素开始倒序输出,每个元素输出7位数组,用0补位
//
count = length -1;
while (*(pointer+count) == 0)
{
count--;
}

printf("%d", *(pointer+count--));

for (; count >= 0; count--)
{
printf("%07d", *(pointer+count));
}

return 0;
}
//
// 计算阶乘的函数
//
void factory( int *a, const int l, const int n )
{
int count = 0;// 计数器
int mul = 0;// 乘数
int upper = 0;// 进位计数器
int temp = 0;// 临时存储器
for (count = 0; count < l; count++)
{
*(a+count) = 0;
}
*a = 1;

//
// 数组中每个元素存储7位数字
//
for (mul = 1; mul <= n; mul++)
{
upper = 0;
for (count = 0; count < l; count++)
{
temp = *(a+count) * mul + upper;
*(a+count) = temp % MAX;
upper = temp / MAX;
}
}
}

太多了,错误应该没有,注释可能少了点,实在太多了。自己仔细看看吧。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-12-19
1,2已调试通过
1.
#include<stdio.h>
float f(int n)
{
int i;
float sum=0;
for(i=1;i<=n;i++)
sum=sum+1.0/(4*i-3)-1.0/(4*i-1);
return sum*4;

}
main()
{
int n;
float p;
printf("请输入n值");
scanf("%d",&n);
p=f(n);
printf("n对应的π值为:%f",p);
}
2.
#include<stdio.h>
main()
{
struct student{
char name[50];
float math,chinese,English,sum;
}s[3],t;
int i,j;
printf("请分别输入三个学生的姓名,数学成绩,语文成绩,英语成绩");
for(i=0;i<3;i++)
scanf("%s%f%f%f", s[i].name, &s[i].math, &s[i].chinese, &s[i].English);
for(i=0;i<3;i++)
s[i].sum=s[i].math+s[i].chinese +
s[i].English;
for(i=0;i<3;i++)
for(j=i;j<3;j++)
if(s[i].sum>s[j].sum)
{
t=s[i];
s[i]=s[j];
s[j]=t;
}
printf("姓名 数学 语文 英语 总分\n");
for(i=0;i<3;i++)
printf("%s %f %f %f %f\n",s[i].name,s[i].math,s[i].chinese,s[i].English,s[i].sum);
}
3。题意不明
第2个回答  2008-12-20
3用递归好了,但是这题出的明显有问题,c的字节长度明显算不到100的阶乘,算到20就不错了
相似回答