13.4从键盘输入一个字符串,将其中的小写字母全部转换成大写字母,然后输出到一个磁盘文件“test”中保存正凳。输入的字符串以“!”结束。
解:#include <stdio.h>
main()
{
File *fp
Char str[100]
Int I=0
If((fp=fopen(“test”,”w”)==NULL)
{printf(“Can not open the 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)
fp=fopen(“test”,”r”)
fgets(str,strlen(str)+1,fp)
printf(“%s\n”,str)
fclose(fp)
}
13.5有两个磁盘文件”A”和”B”,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列),举启旅输出到一个新文件”C”中。
解:#include<stdio.h>
main()
{
FILE *fp
Int I,j,n,i1
Char c[100],t ,ch
If((fp=fopen(“a1”,”r”))==NULL)
{printf(“can not open the file\n”)
exit(0)
}
printf(“\n file A:\n”)
for(I=0(ch=fgetc(fp)!=EOFI++)
{c[i]=ch
putchar(c[i])
}
fclose(fp)
i1=I
if((fp=fopen(“b1”,”r”))==NULL)
{printf(“\n can not ipen the file”)
exit(0)
}
printf(“\n file B:\n”)
for(I=i1(ch=fgenc(fp))!=EOFI++)
{c[i]=ch
putchar(c[i])
}
fclose(fp)
n=I
for(i=0I<nI++)
for(j=I+1j<nj++)
if(c[i]>c[j])
{t=c[i]
c[i]=c[j]
c[j]=t
printf(“\n file C:\n”)
fp=fopen(“c1”,”w”)
for(I=0I<nI++)
{putc(c[i],fp)
putchar(c[i])
}
fclose(fp)
}
13.6有5个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号、姓名、三门课成绩),计算出平均成绩,将原有数据和计算出的平均分数存放在旁烂磁盘文件stud中。
解:
#include<stdio.h>
struct student
{char num[10]
char name[8]
int score[3]
float ave
}stu[5]
main()
{int I,j,sum
FILE *fp
For(I=0I<5I++)
{printf(“\n input score of student%d:\n”,I+1)
printf(“NO.:”)
scanf(“%s”,stu[i].num)
printf(“name:”)
scanf(“%s”,stu[i].name)
sum=0
for(j=0j<3j++)
{printf(“score %d :”j+1)
scanf(“%d”,&stu[i].score[j])
sum+=stu[i].score[j]
}
stu[i].ave=sum/3.0
}
fp=fopen(“stud”,”w”)
for(I=0I<5I++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf(“File write error\n”)
fclose(fp)
fp=fopen(“stud”,”r”)
for(I=0I<5I++)
{fread(&stu[i],sizeof(struct student),1,fp)
printf(“%s,%s,%d,%d,%d,%6.2f\n”,stu[i].num,stu[i].name,stu[i].score[0], stu[i].score[1], stu[i].score[2] ,stu[i].ave)
}
}
13.7将上题stud文件中的学生数据按平均分进行排序处理,并将已排序的学生数据存入一个新文件stu-sort中。
解:
#include <stdio.h>
#define N 10
struct student
{char num[10]
char name[8]
int score[3]
float ave
}st[N],temp
main()
{
FILE *fp
Int I,j,n
If((fp=fopen(“stud”,”r”))==NULL)
{printf(“can not open the file”)
exit(0)
}
printf(“\n file ‘stud’:”)
for(I=0fread(&st[i],sizef(struct student),1,fp)!=0I++)
{printf(“\n%8s%8s”,st[i].num,,st[i].name)
for(j=0j<3j++)
printf(“%8d”,st[i].score[j])
printf(“%10.f”,st[i].ave)
fclose(fp)
n=I
for(I=0I<nI++)
for(j=I+1j<nj++)
if(st[i].ave<st[j].ave)
{temp=st[i]
st[i]=st[j]
st[j]=temp
}
printf(“\nnow:”)
fp=fopen(“stu-sort”,”w”)
for(I=0I<nI++)
{fwrite(&st[i],sizeof(struct student),1,fp)
printf(“\n%8s%8s”,st[i].num,st[i].name)
for(j=0j<3j++)
printf(“%8d”,st[i].score[j])
printf(“%10.2f”,st[i].ave)
fclose(fp)
}
13.8将上题以排序的学生成绩文件进行插入处理。插入一个学生的3门课成绩,程序先计算新插入学生的平均成绩,然后将它按平均成绩高低顺序插入,插入后建立一个新文件。
解:#include <stdio.h>
struct student
{char num[10]
char name[8]
int score[3]
float ave
}st[10],s
main()
{FILE *fp, * fp1
int I,j,t,n
printf(“\n NO.:”)
scanf(“%s”,s.num)
printf(“name:”)
scanf(“%s”,s.name)
printf(“score1,score2,score3:”)
scanf(“%d,%d,%d”,&s. score[0], &s. score[1], &s. score[2])
s.ave=(s.score[0]+s.score[1]+s.score[2])/3.0
if((fp=fopen(“stu_sort”,”r”))==NULL)
{printf(“can not open file.”)
exit(0)
}
printf(“original data:\n”)
for(I=0fread(&st[i],sizeof(struct student),1,fp)!=0I++)
{printf(“\n%8s%8s”,st[i].num,st[i].name)
for(j=0j<3j++)
printf(“%8d”,st[i].score[j])
printf(“%10.2f”,st[i].ave)
}
n=I
for(t=0st[t].ave>s.ave&&t<nt++)
printf(“\nnow:\n”)
fp1=fopen(“sort1.dat”,”w”)
for(I=pj<tI++)
{fwrite(&st[i],sizeof(stuct student),1,fp1)
print(“\n%8s%8s”,st[i],num,st[i].name)
for(j=0j<3j++)
ptintf(“%8d”,st[i].score[j])
printf(“%10.2f”,st[i].ave)
}
fwrite(&s,sizeof(struct student),1,fp1)
printf(“\n%8s%7s%7d%7d%7d%10.2f”,s.num,s.name,s.score[0],s.score[1],s.score[2],s.ave)
for(I=tI<nI++)
{fwrite(&st[i],sizeof(struct student),1,fp1)
printf(“\n %8s%8s”,st[i].num,st[i].name)
for(j=0j<3j++)
printf(“%8d”,st[i].score[j])
printf(“10.2f”,st[i].ave)
fclose(fp)
fclose(fp1)
}
13.9上题结果仍存入原有的stu_sort文件而不另建立新文件。
解: #include<stdio.h>
struct student
{char num[10]
char name[8]
int score[3]
float ave
}st[10],s
main()
{FILE *fp, *fp1
int I ,j,t,n
printf(“\nNO.:”)
scanf(“%s’,s.num)
printf(“name:”)
scanf(“%s’,s.name)
printf(“score1,score2,score3:”)
scanf(“%d%d%d”,&s.score[0]+&s.score[1]+&s.score[1], &s.score[2])
s.ave=( s.score[0]+ s.score[1]+ s.score[2])/3.0
if((fp=fopen(“stu=sort”,”r”))==NULL)
{printf(“can not open the file.”)
exit(0)
}
printf(“original data:\n”)
for(I=0fread(&st[i],sizeof(struct student),1,fp)!=0I++)
{printf(“\n%8s%8s”,st[i].num,st[i].name)
for(j=0j<3j++)
printf(“%8d”,st[i].score[j])
printf(“%10.2f”,st[i].ave)
}
fclose(fp)
n=I
for(t=0st[t].ave>s.ave+&&t<nt++)
ptintf(“\nnow:\n”)
fp=fopen(“stu_sort”,”w”)
for(I=0I<tI++)
{fwrite(&st[i],sizeof(struct student),1,fp)
printf(“\n%9s%8s%8d%8d%8d%10.2f”,s.num,s.name,s.score[0],s.score[1] s.score[2] s.ave)
for(I=tI<nI++)
{fwrit(&sr[i],sizeof(struct srudent),1,fp)
printf(“\n %8s%8s”,st[i].num,st[i].name)
for(j=0j<3j++)
printf(“%8d”,st[i].score[j])
printf(“%10.2f”,st[i].ave)
}
fclose(fp)
}
13.10 有一磁盘文件emploee,内存放职工的数据。每个职工的数据包括:职工姓名、职工号、性别、年龄、住址、工资、健康状况、文化程度。要求将职工名和工资的信息单独抽出来另建一个简明的职工工资文件。
解:#include<stdio.h>
struct emploee
{char num[6]
char name[10]
char sex[2]
int age
char addr[20]
int salary
char health[8]
char class[10]
}en[10]
struct emp
{char name[10]
int salary
}em-case[10]
main()
{FILE *fp1, *fp2
int I,j
if ((fp1=fopen(“emploee”,”r”))==NULL)
{printf(“can not open the file.”)
exit(0)
}
printf(“\n NO. name sex age addr salary health class\n”)
for(I=0fread(&em[i],sizeof(struct emploee),1,fp1)!=pI++)
{printf(“\n%4s%8s%4s%6s%10s%6s%10s%8s”,em[i].num,em[i].name,em[i].sex, em[i].age, em[i].addr, em[i].salary, em[i].health, em[i].class)
strcpy(em_case[i].name, em[i].name)
em_case[i].salary=en[i].salary
}
printf(“\n\n*****************************************”)
if((fp2=fopen(“emp_salary”,”wb”))==NULL)
{printf(“can not open the file.”)
exit(0)}
for(j=0j<Ij++)
{if(fwrite(&en_case[j],sizeof(struct emp),1,fp2)!=1)
printf(“error!”)
printf(“\n %12s%10d”,em_case[j].name,em_case[j].salary)
}
printf(“\n*******************************************”)
fclose(fp1)
fclose(fp2)
}
13.11从上题的“职工工资文件”中删区一个职工的数据,再存回原文件。
解:#incude <stdio.h>
#incude <string.h>
struct emploee
{char name[10]
int salary
}emp[20]
main()
{FILE *fp
int I,j,n,flag
char name[10]
int salary
if((fp=fopen(“emp_salary”,”rb”))==NULL)
{printf(“can not open file.”)
exit(0)
}
printf(“\n original data:”)
for(I=0fead(&emp[i],sizeof(struct emploee),1,fp)!=0I++)
printf(“\n %8s %7d”,emp[i].name,emp[i].salary)
fclose(fp)
n=I
printf(“\n input name deleted:”)
scanf(“%s”,name)
for(flag=1,I=0flag&&I<nI++)
{if(strcmp(name,emp[i].name)==0)
{for(j=Ij<n-1j++)
{strcmp(name,emp[i].name)==0
{for(j=Ij<n-1j++)
{strcpy(emp[j].name,emp[j+1].name)
emp[j].salary=emp[j+1].salary
}
flag=0
}
}
if(!flag)
n=n-1
else
printf(“\n Now,the content of file:\n”)
fp=fopen(“emp-dalary”,”wb”)
for(I=pI<nI++)
fwrite(&emp[i],sizeof(struct emploee),1,fp)
fclose(fp)
fp=fopen(“emp_salary”,”r”)
for(I=0fread(&emp[i],sezeof(struct emploee),1,fp)!=0I++)
printf(“\n%8s%7d”,emp[i].name,emp[i].salary)
fclose(fp)
}
13.12 从键盘输入若干行字符(每行长度不等),输入后把它们存储到一磁盘文件中。再从该文件中读入这些数据,将其中小写字母转换成大写字母后在显示屏上输出。
解: #include<stdio.h>
main()
{int I,flag
char str[80],c
FILE *fp
Fp=fopen(“text”,”w”)
Flag=1
While(flag==1)
{printf(“\n Input string:\n”)
ges(str)
fprintf(fp,”%s”,str)
printf(“\nContinue?”)
c=getchar()
if((c==’N’)||(c==’n’))
flag=0
getchar()
}
fcolse()fp
fp=fopen(“text”,”r”)
while(fscanf(fp,”%s”,str)!=EOF)
{for(I=0str[i]!=’\0’I++)
if((str[i]>=’a’)&&(str[i]<=’z’))
str[i]-=32
printf(“\n%s\n”,str)
}
fclose(fp)
}
6.7完数main()
#include M 1000/*定义寻找枣没败范围*/
main()
{
int k0,k1,k2,k3,k4,k5,k6,k7,k8,k9
int i,j,n,s
for(j=2j<凳颤察迅=Mj++)
{
n=0
s=j
for(i=1i<ji++)
{
if((j%i)==0)
{
if((j%i)==0)
{
n++
s=s-i
switch(n)/*将每个因子赋给k0,k1…k9*/
{
case 1:
k0=i
break
case 2:
k1=i
break
case 3:
k2=i
break
case 4:
k3=i
break
case 5:
k4=i
break
case 6:
k5=i
break
case 7:
k6=i
break
case 8:
k7=i
break
case 9:
k8=i
break
case 10:
k9=i
break
}
}
}
if(s==0)
{
printf("%d是一个‘完数’,它的因子是",j)
if(n>1)
printf("%d,%d",k0,k1)
if(n>2)
printf(",%d",k2)
if(n>3)
printf(",%d",k3)
if(n>4)
printf(",%d",k4)
if(n>5)
printf(",%d",k5)
if(n>6)
printf(",%d",k6)
if(n>7)
printf(",%d",k7)
if(n>8)
printf(",%d",k8)
if(n>9)
printf(",%d",k9)
printf("\n")
}
}
方法二:此题用数组方法更为简单.
main()
{
static int k[10]
int i,j,n,s
for(j=2j<=1000j++)
{
n=-1
s=j
for(i=1i<ji++)
{
if((j%i)==0)
{
n++
s=s-i
k[n]=i/*将每个因子赋给k0,k1...k9*/
}
}
if(s==0)
{
printf("%d是一个完数,它的因子是:",j)
for(i=0i<ni++)
printf("%d,",k[i])
printf("%d\n",k[n])
}
}
5.8 有一个分数序列:2/1,3/2,5/3,8/5……求出这个数列的前20项之和.
解: main()
{
int n,t,number=20
float a=2,b=1,s=0
for(n=1n<=numbern++)
{
s=s+a/b
t=a,a=a+b,b=t
}
printf("总和=%9.6f\n",s)
}
6.9球反d问题
main()
{
float sn=100.0,hn=sn/2
int n
for(n=2n<=10n++)
{
sn=sn+2*hn/*第n次落地时共经过的米数*/
hn=hn/2/*第n次反跳高度*/
}
printf("第10次落地时共经过%f米 \n",sn)
printf("第10次反d%f米.\n",hn)
}
6.10猴子吃桃
main()
{
int day,x1,x2
day=9
x2=1
while(day>0)
{
x1=(x2+1)*2
x2=x1
day--
}
printf("桃子总数=%d\n",x1)
}
6.14打印图案
main()
{
int i,j,k
for(i=0i<=3i++)
{
for(j=0j<=2-1j++)
printf(" ")
for(k=0k<=2*ik++)
printf("*")
printf("\n")
}
for(i=0i<=2i++)
{
for(j=0j<=ij++)
printf(" ")
for(k=0k<=4-2*ik++)
printf("*")
printf("\n")
}
6.15乒乓比赛
main()
{
char i,j,k/*i是a是对手j是b是对手k是c的对手*/
for(i='x'i<='z'i++)
for(j='x'j<='z'j++)
{
if(i!=j)
for(k='x'k<='z'k++)
{
if(i!=k&&j!=k)
{if(i!='x' &&k!='x' &&k! ='z')
printf("顺序为:\na-%c\tb--%c\tc--%c\n",i,j,k)
}
}
}
}
7.1用筛选法求100之内的素数.
/*用筛选法求100之内的素数*/
#include<math.h>
#define N 101
main()
{int i,j,line,a[N]
for(i=2i<Ni++) a[i]=i
for(i=2i<sqrl(N)i++)
for(j=i+1j<Nj++)
{if(a[i]!=0 &&a[j]!=0)
if(a[j]%a[i]==0)
a[j]=0
printf("\n")
for(i=2,line=0i<Ni++)
{ if(a[i]!=0)
{printf("%5d",a[i])
line++
if(line==10)
{printf("\n")
line=0}
}
}
7.2用选择法对10个数排序.
/*选择法排序.*/
#define N 10
main()
{ int i,j,min,temp,a[N]
/*输入数据*/
printf("请输入十个数:\n")
for (i=0i<Ni++)
{ printf("a[%d]=",i)
scanf("%d",&a[i])
}
printf("\n")
for(i=0i<Ni++)
printf("%5d",a[i])
printf("\n")
/*排序*/
for (i=0i<N-1i++)
{ min=i
for(j=i+1j<Nj++)
if(a[min]>a[j]) min=j
temp=a[i]
a[i]=a[min]
a[min]=temp
}
/*输出*/
printf("\n排序结果如下:\n")
for(i=0i<Ni++)
printf("%5d",a[i])
}
7.3对角线和:
/*计算矩阵对角线元素之和*/
main()
{
float a[3][3],sum=0
int i,j
printf("请输入矩阵元素:\n")
for(i=0i<3i++)
for(j=0j<3j++)
scanf("%f",&a[i][j])
for(i=0i<3i++)
sum=sum+a[i][i]
printf("对角元素之和=6.2f",sum)
}
7.4插入数据到数组
/*插入数据到数组*/
main()
{int a[11]={1,4,6,9,13,16,19,28,40,100}
int temp1,temp2,number,end,i,j
printf("初始数组如下:")
for (i=0i<10i++)
printf("%5d",a[i])
printf("\n")
printf("输入插入数据:")
scanf("%d",&number)
end=a[9]
if(number>end)
a[10]=number
else
{for(i=0i<10i++)
{ if(a[i]>number)
{temp1=a[i]
a[i]=number
for(j=i+1j<11j++)
{temp2=a[j]
a[j]=temp1
temp1=temp2
}
break
}
}
}
for(i=0j<11i++)
printf("a%6d",a[i])
}
7.5将一个数组逆序存放。
/*数组逆序存放*/
#define N 5
main()
{ int a[N]={8,6,5,4,1},i,temp
printf("\n 初始数组:\n")
for(i=0i<Ni++)
printf("%4d",a[i])
for(i=0i<N/2i++)
{ temp=a[i]
a[i]=a[N-i-1]
a[N-i-1]=temp
}
printf("\n 交换后的数组:\n")
for(i=0i<Ni++)
printf("%4d",a[i])
}
7.6杨辉三角
/*打印杨辉三角形*/
#define N 11
main()
{ int i,j,a[N][N]
for(i=1i<Ni++)
{a[i][i]=1
a[i][1]=1
}
for(i=3i<Ni++)
for(j=2j<=i-1j++)
a[i][j]=a[i01][j-1]+a[i-1][j]
for(i=1i<Ni++)
{ for(j=1j<=ij++)
printf("%6d",a[i][j]
printf("\n")
}
printf("\n")
}
7.8鞍点
/*查找鞍点*/
#define N 10
#define M 10
main()
{ int i,j,k,m,n,flag1,flag2,a[N][M],max,maxi,maxj
printf("\n输入行数n:")
scanf("%d",&n)
printf("\n输入列数m:")
scanf("%d",&m)
for(i=0i<ni++)
{ printf("第%d行?\n",i)
for(j=0j<m,j++)
scanf("%d",&a[i][j]
}
for(i=0i<ni++)
{ for(j=0j<mj++)
printf("%5d",a[i][j])
pritf("\n")
}
flag2=0
for(i=0i<ni++)
{ max=a[i][0]
for(j=0j<mj++)
if(a[i][j]>max)
{ max=a[i][j]
maxj=j
}
for (k=0,flag1=1k<n &&flag1k++)
if(max>a[k][max])
flag1=0
if(flag1)
{ printf("\n第%d行,第%d列的%d是鞍点\n",i,maxj,max)
flag2=1
}
}
if(!flag2)
printf("\n 矩阵中无鞍点! \n")
}
7.9变量说明:top,bott:查找区间两端点的下标loca:查找成功与否的开关变量.
/*折半查找*/
#include<stdio.h>
#define N 15
main()
{ int i,j,number,top,bott,min,loca,a[N],flag
char c
printf("输入15个数(a[i]>[i-1])\n)
scanf("%d",&a[0])
i=1
while(i<N)
{ scanf("%d",&a[i])
if(a[i]>=a[i-1])
i++
esle
{printf("请重输入a[i]")
printf("必须大于%d\n",a[i-1])
}
}
printf("\n")
for(i=0i<Ni++)
printf("%4d",a[i])
printf("\n")
flag=1
while(flag)
{
printf("请输入查找数据:")
scanf("%d",&number)
loca=0
top=0
bott=N-1
if((number<a[0])||(number>a[N-1]))
loca=-1
while((loca==0)&&(top<=bott))
{ min=(bott+top)/2
if(number==a[min])
{ loca=min
printf("%d位于表中第%d个数\n",number,loca+1)
}
else if(number<a[min])
bott=min-1
else
top=min+1
}
if(loca==0||loca==-1)
printf("%d不在表中\n",number)
printf("是否继续查找?Y/N!\n")
c=getchar()
if(c=='N'||c=='n')
flag=0
}
}
7.10/*统计字符数*/
main()
{ int i,j,uppn,lown,dign,span,othn
char text[3][80]
uppn=lown=dign=span=othn=0
for(i=0i<3i++)
{ printf("\n请输入第%d行:\n",i)
gets(text[i])
for(j=0j<80 &&text[i][j]!='\0'j++)
{if(text[i][j]>='A' &&text[i][j]<='Z')
uppn+=1
else if(text[i][j]>='a' &&text[i][j]<='z')
lown+=1
else if(text[i][j]>='1' &&text[i][j]<='9')
dign+=1
else if(text[i][j]=' ')
span+=1
else
othn+=1
}
}
for(i=0i<3i++)
printf("%s=n",text[i])
printf("大写字母数:%d\n",uppn)
printf("小写字母数:%d\n",lown)
printf("数字个数:%d\n",dign)
printf("空格个数:%d\n",span)
printf("其它字符:%d\n",othn)
}
7.11/*打印图案*/
main()
{static char a[5]={'*','*','*','*','*'}
int i,j,k
char space=' '
for(i=0i<=5i++)
{printf("\n")
for(j=1j<=3*ij++)
printf("%lc",space)
for(k=0k<=5k++)
printf("%3c",a[k]
}
}
7.12/*译电文*/
#include<stdio.h>
main()
{int i,n
char ch[80],tran[80]
printf("请输入字符:")
gets(ch)
printf("\n密码是%c",ch)
i=0
while(ch[i]!='\0')
{if((ch[i]>='A')&&(ch[i]<='Z'))
tran[i]=26+64-ch[i]+1+64
else if((ch[i]>='a')&&(ch[i]<='z'))
tran[i]=26+96-ch[i]+1+96
else
tran[i]=ch[i]
i++
}
n=i
printf("\n原文是:")
for(i=0i<ni++)
putchar(tran[i])
}
7.13/*连接两个字符串(不用'stract')*/
main()
{
char s1[80],s2[40]
int i=0,j=0
printf("\n请输入字符串1:")
scanf("%s",s1)
printf("\n请输入字符串2:")
scanf("%s",s2)
while(s1[i]!='\0')
i++
while(s2[j]!='\0')
s1[i++]=s2[j++]
s1[i]='\0'
printf("\n连接后字符串为:%s",s1)
}
7.14/*字符串比较*/
#include<stdio.h>
main()
{int i,resu
char s1[100],s2[100]
printf("请输入字符串1:\n")
gets(s1)
printf("\n 请输入字符串2:\n")
gets(s2)
i=0
while((s1[i]==s2[i]) &&(s1[i]!='\0'))i++
if(s1[i]=='\0' &&s2[i]=='\0')resu=0
else
resu=s1[i]-s2[i]
printf(" %s与%s比较结果是%d",s1,s2,resu)
}
7.15/*字符串复制*/
#include<stdio.h>
main()
{
char from[80],to[80]
int i
printf("请输入字符串")
scanf("%s",from)
for(i=0i<=strlen(from)i++)
to[i]=from[i]
printf("复制字符串为:%s\n",to)
}
第八章 函数
8.1(最小公倍数=u*v/最大公约数.)
hcf(u,v)
int u,v
(int a,b,t,r
if(u>v)
{t=uu=vv=t}
a=ub=v
while((r=b%a)!=0)
{b=aa=r}
return(a)
}
lcd(u,v,h)
int u,v,h
{int u,v,h,l
scanf("%d,%d",&u,&v)
h=hcf(u,v)
printf("H.C.F=%d\n",h)
l=lcd(u,v,h)
printf("L.C.d=%d\n",l)
}
{return(u*v/h)}
main()
{int u,v,h,l
scanf("%d,%d",&u,&v)
h=hcf(u,v)
printf("H.C.F=%d\n",h)
l=lcd(u,v,h)
printf("L.C.D=%d\n",l)
}
8.2求方程根
#include<math.h>
float x1,x2,disc,p,q
greater_than_zero(a,b)
float a,b
{
x1=(-b+sqrt(disc))/(2*a)
x2=(-b-sqrt(disc))/(2*a)
}
equal_to_zero(a,b)
float a,b
{x1=x2=(-b)/(2*a)}
smaller_than_zero(a,b)
float a,b
{p=-b/(2*a)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)