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

作者&投稿:太路 (联系方式在网页底部的电邮联系)
C语言编程题 急急急急~

#includeint main(){int a[10],n,b[10],flag=0;printf("输入一个正整数n(1<n<=10)
");scanf("%d",&n);printf("输入%d个整数
",n);for(int i=0;i<n;i++){scanf("%d",&a[i]);}for(int i=0;i<n-1;i++){b[i]=a[i+1]/a[i];}printf("数组b中的各个元素为
");for(int i=0;i<n-1;i++){flag++;printf("%d ",b[i]);if(flag==3){flag=0;printf("
");}}printf("
"); }
请采纳

1)

#include
int main()
{
int n;
scanf("%d",&n);
if(n%2==1)n++;
else n+=2;
printf("%d
",n);
system("pause");

return 0;
}

2)
#include
int main()
{
int n,m;
scanf("%d %d",&n,&m);
if(n%m==0)printf("%d是%d的倍数
",n,m);
else printf("%d不是%d的倍数
",n,m);
system("pause");

return 0;
}

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,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。题意不明

3用递归好了,但是这题出的明显有问题,c的字节长度明显算不到100的阶乘,算到20就不错了

相关视频

请用C语言程序编程,高手请帮忙!有重金赏!请看下面题目:
这个阶梯有119步,程序如下:main(){ int x=7;while (x%2!=1 || x%3!=2 || x%4!=3 || x%5!=4 || x%6!=5) x+=7;printf("%d\\n",x);} 程序根据7步刚好走完这一信息,从7开始测试是否满足要求,不满足就加7再测试,知道满足为止。FOR...

C语言程序设计 我是C语言初学者,有一道看程序的题我有些弄不懂,还请...
答案:C A:是如果a>b,则一程序一直执行到“b=c;”,效果是换a与b的值;B:是如果a>b,则执行{ }里的语句,效果是交换a与b的值;C:是如果a>b,则执行c=a; 无论a是否大于b,c的值都要给a,a-b;没什么作用;D:是如果a>b,则效果是交换a与b的值,c相当于中转站,a-b;没什么...

请高手用C语言帮忙做个编程的题目,谢谢了!
include <stdio.h> int IsDevided(int number,int dev){ if(number %dev == 0){ return 1;} return 0;} void EasyDone(int a){ int chose;int i,j;printf("Input your chose\\n1>能被3整除的"<Enter 1>","\\n2>能被5整除的<Enter 2>","\\n3>能被3或5整除的<Enter 3>\\n");s...

c语言编程高手请进:麻烦帮忙解决下面这个菜鸟级的问题!(两个问题),求...
首先:#include"stdio.h"int fun(int i, int n){ int m=1;for(int j=0;j0){ a=j%10;if(a%7==0)s++;j=j\/10;} printf(" %d中有%d个7",x,s);} 第一题include"stdio.h"int fun(int i, int n){int m=1;for(int j=0;j0)...