Created
May 21, 2013 12:46
-
-
Save junstrix/5619523 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main () | |
{ | |
float h,r,l,s,sq,vq,vz; | |
float pi=3.141526; | |
printf("请输入圆半径r,圆柱高h∶"); | |
scanf("%f,%f",&r,&h); //要求输入圆半径r和圆柱高h | |
l=2*pi*r; //计算圆周长l | |
s=r*r*pi; //计算圆面积s | |
sq=4*pi*r*r; //计算圆球表面积sq | |
vq=4.0/3.0*pi*r*r*r; //计算圆球体积vq | |
vz=pi*r*r*h; //计算圆柱体积vz | |
printf("圆周长为: l=%6.2f\n",l); | |
printf("圆面积为: s=%6.2f\n",s); | |
printf("圆球表面积为: sq=%6.2f\n",sq); | |
printf("圆球体积为: v=%6.2f\n",vq); | |
printf("圆柱体积为: vz=%6.2f\n",vz); | |
return 0; | |
} | |
#include <stdio.h> | |
int main() | |
{ | |
int x,y; | |
printf("输入x:"); | |
scanf("%d",&x); | |
if(x<1) /* x<1 */ | |
{ | |
y=x; | |
printf("x=%3d, y=x=%d\n" ,x,y); | |
} | |
else if(x<10) /* 1=<x<10 */ | |
{ | |
y=2*x-1; | |
printf("x=%d, y=2*x-1=%d\n",x,y); | |
} | |
else /* x>=10 */ | |
{ | |
y=3*x-11; | |
printf("x=%d, y=3*x-11=%d\n",x,y); | |
} | |
return 0; | |
} | |
#include <stdio.h> | |
int main() | |
{ | |
float score; | |
char grade; | |
printf("请输入学生成绩:"); | |
scanf("%f",&score); | |
while (score>100||score<0) | |
{ | |
printf("\n 输入有误,请重输"); | |
scanf("%f",&score); | |
} | |
switch((int)(score/10)) | |
{ | |
case 10: grade='A';break; | |
case 9: grade='A';break; | |
case 8: grade='B';break; | |
case 7: grade='C';break; | |
case 6: grade='D';break; | |
default: grade='E'; | |
} | |
printf("成绩是 %5.1f,相应的等级是%c\n ",score,grade); | |
return 0; | |
} | |
#include <stdio.h> | |
int main() | |
{ | |
int p,r,n,m,temp; | |
printf("请输入两个正整数n,m:"); | |
scanf("%d,%d,",&n,&m); | |
if (n<m) | |
{ | |
temp=n; | |
n=m; | |
m=temp; | |
} | |
p=n*m; | |
while(m!=0) | |
{ | |
r=n%m; | |
n=m; | |
m=r; | |
} | |
printf("它们的最大公约数为:%d\n",n); | |
printf("它们的最小公约数为:%d\n",p/n); | |
return 0; | |
} | |
#include <stdio.h> | |
#include <math.h> | |
int main() | |
{ | |
float a,x0,x1; | |
printf("enter a positive number:"); | |
scanf("%f",&a); | |
x0=a/2; | |
x1=(x0+a/x0)/2; | |
do | |
{ | |
x0=x1; | |
x1=(x0+a/x0)/2; | |
}while(fabs(x0-x1)>=1e-5); | |
printf("The square root of %5.2f is %8.5f\n",a,x1); | |
return 0; | |
} | |
#include <stdio.h> | |
int main() | |
{ | |
int i,j,min,temp,a[11]; | |
printf("enter data:\n"); | |
for (i=1;i<=10;i++) | |
{ | |
printf("a[%d]=",i); | |
scanf("%d",&a[i]); | |
} | |
printf("\n"); | |
printf("The orginal numbers:\n"); | |
for (i=1;i<=10;i++) | |
printf("%5d",a[i]); | |
printf("\n"); | |
for (i=1;i<=9;i++) | |
{ | |
min=i; | |
for (j=i+1;j<=10;j++) | |
if (a[min]>a[j]) min=j; | |
temp=a[i]; | |
a[i]=a[min]; | |
a[min]=temp; | |
} | |
printf("\nThe sorted numbers:\n"); | |
for (i=1;i<=10;i++) | |
printf("%5d",a[i]); | |
printf("\n"); | |
return 0; | |
} | |
#include <stdio.h> | |
int main() | |
{ | |
int i,j,upp,low,dig,spa,oth; | |
char text[3][80]; | |
upp=low=dig=spa=oth=0; | |
for (i=0;i<3;i++) | |
{ | |
printf("please input line %d:\n",i+1); | |
gets(text[i]); | |
for (j=0;j<80 && text[i][j]!='\0';j++) | |
{ | |
if (text[i][j]>='A'&& text[i][j]<='Z') | |
upp++; | |
else if (text[i][j]>='a' && text[i][j]<='z') | |
low++; | |
else if (text[i][j]>='0' && text[i][j]<='9') | |
dig++; | |
else if (text[i][j]==' ') | |
spa++; | |
else | |
oth++; | |
} | |
} | |
printf("\nupper case: %d\n",upp); | |
printf("lower case: %d\n",low); | |
printf("digit : %d\n",dig); | |
printf("space : %d\n",spa); | |
printf("other : %d\n",oth); | |
return 0; | |
} | |
#include <stdio.h> | |
#include <math.h> | |
float x1,x2,disc,p,q; | |
int main() | |
{ | |
void greater_than_zero(float,float); | |
void equal_to_zero(float,float); | |
void smaller_than_zero(float,float); | |
float a,b,c; | |
printf("input a,b,c:"); | |
scanf("%f,%f,%f",&a,&b,&c); | |
printf("equation: %5.2f*x*x+%5.2f*x+%5.2f=0\n",a,b,c); | |
disc=b*b-4*a*c; | |
printf("root:\n"); | |
if (disc>0) | |
{ | |
greater_than_zero(a,b); | |
printf("x1=%f\t\tx2=%f\n",x1,x2); | |
} | |
else if (disc==0) | |
{ | |
equal_to_zero(a,b); | |
printf("x1=%f\t\tx2=%f\n",x1,x2); | |
} | |
else | |
{ | |
smaller_than_zero(a,b); | |
printf("x1=%f+%fi\tx2=%f-%fi\n",p,q,p,q); | |
} | |
return 0; | |
} | |
void greater_than_zero(float a,float b) | |
{ | |
x1=(-b+sqrt(disc))/(2*a); | |
x2=(-b-sqrt(disc))/(2*a); | |
} | |
void equal_to_zero(float a,float b) | |
{ | |
x1=x2=(-b)/(2*a); | |
} | |
void smaller_than_zero(float a,float b) | |
{ | |
p=-b/(2*a); | |
q=sqrt(-disc)/(2*a); | |
} | |
#include <stdio.h> | |
#include <string.h> | |
#define N 10 | |
char str[N]; | |
int main() | |
{ | |
void sort(char []); | |
int i,flag; | |
for (flag=1;flag==1;) | |
{ | |
printf("input string:\n"); | |
scanf("%s",&str); | |
if (strlen(str)>N) | |
printf("string too long,input again!"); | |
else | |
flag=0; | |
} | |
sort(str); | |
printf("string sorted:\n"); | |
for (i=0;i<N;i++) | |
printf("%c",str[i]); | |
printf("\n"); | |
return 0; | |
} | |
void sort(char str[]) | |
{ | |
int i,j; | |
char t; | |
for(j=1;j<N;j++) | |
for (i=0;(i<N-j)&&(str[i]!='\0');i++) | |
if(str[i]>str[i+1]) | |
{ | |
t=str[i]; | |
str[i]=str[i+1]; | |
str[i+1]=t; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment