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语言编程题,请高手帮忙做一下,拜谢,急急急急……视频

相关评论:
  • 15230472319c语言编程题,请高手帮忙做一下,拜谢,急急急急……
    家灵李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 st...

  • 15230472319C语言高手请进,帮帮我吧,谢谢啦!!!
    家灵李5*i+3*j+k\/3 第五题:6 第六题:0,0 第七题:1 ,3, 3, 5 第八题:sum1=27,sum2=15 \/\/不知道我做错没有.错了请多指教!

  • 15230472319请高手用C语言帮忙做个编程的题目,谢谢了!
    家灵李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");scanf("%d",&chose)...

  • 15230472319请c语言高手帮我计算下答案多少?我算出来是6
    家灵李while (k <= j \/ 2 && b) { ++k; b = j % k; } 只有j等于7才能导致最后跳出循环时b非0.6,9,8都不行.

  • 15230472319求高手帮忙做一些C语言试题
    家灵李第一题、单项选择题(每题1分,5道题共5分)1、设x和y均为int型变量,则以下语句:x=x+y; y=x-y; x=x-y; 的功能是:D、交换x和y中的值 2、已说明int a=256,执行语句printf(”%x” ,a);的结果是:A、100 3、以下合法的赋值语句是:A、x=y=100;4、已说明int a=...

  • 15230472319[急求助]C语言程序编程题,请高手帮忙解答下。!
    家灵李fun(int a,int b,long c){ c=a%10*100+a\/10+b\/10*1000+b%10*10;\/*解释:a%10的意思是a除以10剩下的余数,即a的个位数,若a是45,a%10就是5,再乘以100即是500;a\/10就是十位数,即4,原因是它是向下取整,45\/10虽是4.5,但向下取整就将小数点后的都等于零;b\/10和上面的a一...

  • 15230472319紧急求救:考试要用到的八道c语言的编程题 请高手帮忙给出答案,最好是...
    家灵李return 1;} \/*2 有一个字符数组str,数组中存放一个字符串,编程将字符数组中ASCII值为奇数的字符从数组中删除掉,删除后形成的新字符串仍然存放在原来的字符数组str中。\/ include<stdio.h> main(){ char ch[10];int i,num[10],j,k;for(i=0;i<10;i++){ ch[i]=i+30; \/\/这只...

  • 15230472319求各位高手帮忙作一下C语言作业
    家灵李所有程序在win-tc和Dev-c++下运行通过。现在所有的题目都有答案了。第一题:include <stdio.h> define N 10 int main(){ int a[N],i,m=0,n=0,max,min,*p;p=a;printf("Please input %d elements of the matrix :\\n",N);for(i=0;i<N;i++)scanf("%d",p+i);printf("The array...

  • 15230472319C语言的几道考题,请各位高手帮忙,急!!!(追加50分)
    家灵李三题我答案和你的一样 四题 五题的S=0没什么作用,可以不写,最后的GETCH也可不写,我是没发现有什么用。六题 include<stdio.h> int stu(int a,int b,int c);int stu(int a,int b,int c){ int s;s=a*a+b*b+c*c;return s;} void main(){ int a,b,c;printf("请输入3个...

  • 15230472319电脑C语言编程,求高手帮忙
    家灵李1.include<stdio.h> void main(){ int n[8],maxn=0,minn=0,detn;float score[8],max,min,aver=0.0,det,detm;printf("输入裁判号及分数:\\n");scanf("%d%f",&n[0],&score[0]);max=min=score[0];for(int i=1;i<8;i++){ scanf("%d%f",&n[i],&score[i]);if(max<...

  • 相关主题精彩

    版权声明:本网站为非赢利性站点,内容来自于网络投稿和网络,若有相关事宜,请联系管理员

    Copyright © 喜物网