A. 一道c语言编程题,各位大神帮帮忙啊!
代码如下:
#include<stdio.h>
#include<stdlib.h>
intmain()
{
intscore=0,sum=0,max=0,min=100,count=0,aver=0;
printf("请输入学生成绩:");
scanf("%d",&score);
while(score>=0&&score<=100){
sum+=score;
if(score>max){
max=score;
}
if(score<min){
min=score;
}
count++;
scanf("%d",&score);
}
printf("共录入了%d个学生成绩。 ",count);
printf("最高分:%d ",max);
printf("最低分:%d ",min);
printf("平均分:%d ",sum/count);
system("pause");
return0;
}
B. 用C语言编写1ms延迟子程序,不明白for (j=0;j<120;j++),求助大大们
void delay1ms(int x)//延迟函数开始
{
int i,j;
for (i=0;i<x;i++) //计数x次,延迟x 1ms
for (j=0;j<120;j++); //计数120次,延迟1ms
}
这是一个for循环嵌套,每执行一次第一个for语句,那么第二个for语句要执行120次
for (j=0;j<120;j++); 就是没执行一次第一个for循环,就令 j =0,再判断是否 j 满足循环条件(这里就是判断是否 j 小于120)如果满足就继续循环,如果不满足就跳出循环。
C. C语言初学编程问题 排序问题!求助 感谢!
#include<stdio.h> //冒泡排序,从小到大。void sort(int a[], int n) { int i, j; int temp; int len = n; for (i = 0; i < len - 1; i++) for (j = 0; j < len - 1 - i; j++){ if (a[j] > a[j + 1]) { temp = a[j]; a[j] = a[j + 1]; a[j+1] = temp; } } } int main() { int a[5] = {2, 3 ,1, 5, 4}; int i; sort(a, 5); for(i = 0; i < 5; i++) { printf("%d ", a[i]); } printf("\n");}
D. 求助各位C语言编程高手~帮我做3道题~
#include<stdio.h>
#include<string.h>
#defineN4
/*-----------------------------------------
第一题
-------------------------------------------*/
voidDiamond(constchar*s,intn,intlen)
{
printf("%*s%-s\n",len,s+n-1,s+n);
if(n>1)
Diamond(s,n-1,len);
printf("%*s%-s\n",len,s+n,n==len?s+n:s+n+1);
}
/*-----------------------------------------
第二题
-------------------------------------------*/
typedefstruct
{
intgcd;
intlcm;
}pair;
voidGCD_LCM(inta,intb,pair*p)
{
inttmp;
intproct=a*b;
while(b%a)
{
tmp=a;
a=b%a;
b=tmp;
}
p->gcd=a;
p->lcm=proct/a;
}
/*-----------------------------------------
第三题
-------------------------------------------*/
voidSwap(int*lhs,int*rhs)
{
inttmp=*lhs;
*lhs=*rhs;
*rhs=tmp;
}
voidBubbleSort(int*beg,int*end)
{
for(;beg!=end;++beg)
for(int*p=end-1;p!=beg;--p)
if(*p<*(p-1))
Swap(p,p-1);
}
voidSelectSort(int*beg,int*end)
{
for(;beg!=end;++beg)
{
int*max=beg;
for(int*p=beg+1;p!=end;++p)
if(*max<*p)
max=p;
Swap(beg,max);
}
}
voidPrint(int*beg,int*end)
{
while(beg!=end)
printf("%d",*beg++);
putchar('\n');
}
intmain()
{
/*一*/
charpt[N+1]={0};
memset(pt,'*',N);
Diamond(pt,N,N);
/*二*/
pairp;
GCD_LCM(3,6,&p);
printf("%d%d\n",p.gcd,p.lcm);
/*三*/
inta[]={32,9,45,22,15,48,47,8,55,1};
Print(a,a+10);
BubbleSort(a,a+10);
Print(a,a+10);
SelectSort(a,a+10);
Print(a,a+10);
}