//第一题
#include<stdio.h>
double min(double x,double y);
int main()
{
double number1,number2;
scanf("%lf %lf",&number1,&number2);
printf("The lesser of %f and %f is %f",number1,number2,min(number1,number2));
}
double min(double x,double y)
{
return (x<y)?x:y;
}
//第二题
#include<stdio.h>
void chline(char c,int a,int b);
int main()
{
char c;
int line,column;
printf("Please enter the character:\n");
scanf("%c",&c);
printf("Please enter the line and column:\n");
scanf("%d %d",&line,&column);
chline(c,column,line);
}
void chline(char c,int a,int b)
{
int i,j;
for(j=b;j>0;j--){
for(i=a;i>0;i--){
printf("%c",c);
}
printf("\n");
}
}
//第三题和第二题 一样
#include<stdio.h>
void chline(char c,int a,int b);
int main()
{
char c;
int line,column;
printf("Please enter the character:\n");
scanf("%c",&c);
printf("Please enter the line and column:\n");
scanf("%d %d",&line,&column);
chline(c,column,line);
}
void chline(char c,int a,int b)
{
int i,j;
for(j=b;j>0;j--){
for(i=a;i>0;i--){
printf("%c",c);
}
printf("\n");
}
}
//第四题
#include<stdio.h>
double average(double n1,double n2);
int main()
{
double number1,number2;
scanf("%lf %lf",&number1,&number2);
double harmonic_average;
harmonic_average=average(number1,number2);
printf("The harmonic_average of the %lf and %lf is %lf",number1,number2,harmonic_average);
}
double average(double n1,double n2)
{
n1=1/n1;
n2=1/n2;
return 1/((n1+n2)/2);
}
//第五题
#include<stdio.h>
void larger_of(double* x,double* y);
int main()
{
double x,y;
scanf("%lf %lf",&x,&y);
printf("Before: %f %f\n",x,y);
larger_of(&x,&y);
printf("After: %f %f\n",x,y);
}
void larger_of(double* x,double* y)
{
if(*x>*y){
*y=*x;
}else{
*x=*y;
}
}
//第六题
#include<stdio.h>
void sort(double* x,double* y,double*z);
int main()
{
double x,y,z;
scanf("%lf %lf %lf",&x,&y,&z);
printf("Before: %f %f %f\n",x,y,z);
sort(&x,&y,&z);
printf("After: %f %f %f\n",x,y,z);
}
void sort(double* x,double* y,double*z)
{
double temp = 0.0;
if( *x>*y )
{
temp = *x;
*x = *y;
*y = temp;
}
if( *x>*z )
{
temp = *x;
*x = *z;
*z = temp;
}
if( *y>*z )
{
temp = *y;
*y = *z;
*z = temp;
}
}
//第七题
#include<stdio.h>
#include<ctype.h>
int isalpha(char ch);
int main()
{
char ch;
while((ch=getchar())!=EOF){
if(ch=='\n'){
printf("please enter another character");
continue;
}
if(isalpha(ch)!=-1){
printf("alpha %c is %d in alphabet\n",ch,isalpha(ch));
}
}
}
int isalpha(char ch)
{
if(isupper(ch)){
return ch-'A'+1;
}else if(islower(ch)){
return ch-'a'+1;
}else{
return -1;
}
}
//第八题
#include<stdio.h>
#include<math.h>
double power( double x,double y );
int main()
{
double x,y,result;
scanf("%lf %lf",&x,&y);
result=power(x,y);
printf("%lf to the %lf is %lf\n",x,y,result);
return 0;
}
double power( double x,double y )
{
double t;
if(y>0){
return pow(x,y);
}
if(y==0){
if(0==x)
{
printf("0 to the 0 is undefined\n");
}
return 1;
}
if(y<0){
t=pow( x,-y );
return (1/t);
}
}
//第九题
#include<stdio.h>
double power(double x,double y);
int main()
{
double x,y,result;
scanf("%lf %lf",&x,&y);
result=power(x,y);
printf("%lf to the %lf is %lf",x,y,result);
}
double power(double x,double y)
{
double t;
if(y>0){
;
return (x*power(x,--y));
}
if(y==0){
if(x==0){
printf("0 to the 0 is underfined\n");
}
return 1;
}
if(y<0){
t=1/x;
return (t*power(x,++y));
}
}
//第十题
#include<stdio.h>
void to_base_n(int bas,int n);
int main()
{
int bas,n;
scanf("%d %d",&bas,&n);
printf("conver %d to %d is\n",bas,n);
to_base_n(bas,n);
}
void to_base_n(int bas,int n)
{
int x;
x=bas%n;
if(bas>=n){
to_base_n(bas/n,n);
}
printf("%d",x);
}
//第十一题
#include<stdio.h>
void Fibonacci(int n);
int main()
{
int n;
scanf("%d",&n);
Fibonacci(n);
}
void Fibonacci(int n)
{
int i;
int n1,n2;
int t;
n1=1;
n2=1;
for(i=1;i<=n;i++){
if(i==1){
printf("1 ");
}else if(i==2){
printf("1 ");
}else{
t=n1+n2;
n1=n2;
n2=t;
printf("%d ",n2);
}
}
}