//第 1 題
#include<stdio.h>
double min( double x, double y )
{
return ( x < y ? x : y);
}
int main()
{
double x,y,result;
scanf("%lf",&x);
scanf("%lf",&y);
result = min(x,y);
printf("%lf",result);
return 0;
}
//第 2 題
#include <stdio.h>
void chline (char ch, int i, int j)
{
int a,b;
for( a=0 ; a<j ; a++ )
{
for( b=0 ; b<i ; b++ )
{
putchar(ch);
}
putchar('\n');
}
}
int main()
{
char ch;
int i,j;
scanf("%c",&ch);
scanf("%d %d",&i,&j);
chline( ch, i, j);
return 0;
}
//第 3 題
把第二題行和列換一下就行
//第 4 題
#include <stdio.h>
double average( double x , double y )
{
double average;
x = 1/x;//倒數
y = 1/y;
average = (x+y)/2.0;
average = 1/average;
return average;
}
int main()
{
double x,y,aver;
scanf("%lf %lf",&x,&y);
aver = average(x,y);
printf("%lf",aver);
return 0;
}
//第 5 題
#include<stdio.h>
void larger_of( double *a, double *b )
{
int temp;
temp = *a > *b ? *a : *b;
*a = temp;
*b = temp;
}
int main()
{
double x,y;
scanf("%lf %lf",&x,&y);
printf("Before:%lf %lf\n",x,y);
larger_of( &x, &y);
printf("After:%lf %lf\n",x,y);
return 0;
}
//第 6 題
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void sorting(double *a, double *b, double* c);
int main()
{
double x,y,z;
scanf("%lf %lf %lf",&x,&y,&z);
printf("Before:%lf %lf %lf\n",x,y,z);
sorting( &x, &y, &z);
printf("After:%lf %lf %lf\n",x,y,z);
return 0;
}
void sorting(double* a, double* b, double* c)
{
int temp1,temp2,temp3;
temp1 = *c >= (*a > *b ? *a : *b) ? *c : (*a > *b ? *a : *b);
temp3 = *c <= (*a < *b ? *a : *b) ? *c : (*a < *b ? *a : *b);
if (*a <= temp1 && *a >= temp3)
temp2 = *a;
else if (*b <= temp1 && *b >= temp3)
temp2 = *b;
else temp2 = *c;
*a = temp1;
*b = temp2;
*c = temp3;
}
//第 7 題
#include <stdio.h>
int alpha(char ch)
{
if (ch >= 'a' && ch <= 'z')
{
return (ch - 'a' + 1);
}
else if (ch >= 'A' && ch <= 'Z')
{
return (ch - 'A' + 1);
}
else
{
return -1;
}
}
int main(void)
{
char ch;
int alp;
while ((ch = getchar()) != EOF)
{
if ('\n' == EOF)
{
continue;
}
alp = alpha(ch);
if (alp != -1)
{
printf("%c:%d\n", ch, alp);
}
}
return 0;
}
第 8 題
#include<stdio.h>
#include<math.h>
double power( double x,double y )
{
double temp;
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 )
{
temp = pow( x,-y );
return (1/temp);
}
}
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;
}
//第 9 題
#include <stdio.h>
double power(double x,double y)
{
double temp;
if( y>0 )
{
y--;
return (x * power(x,y));
}
if( y==0 )
{
if( x==0 )
{
printf("0 to the 0 is undefined\n");
}
return 1;
}
if( y<0 )
{
y++;
temp = 1/x;
return (temp * power(x,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;
}
//第 10 題
#include <stdio.h>
void to_base_n( int base, int n )
{
int x;
x = base % n;
if( base>=n )
{
to_base_n(base / n, n);
}
printf("%d",x);
}
int main()
{
int base,n;
scanf("%d %d",&base,&n);
printf("When we convert %d to %d,we get ",base,n);
to_base_n(base,n);
return 0;
}
//第 11 題
#include <stdio.h>
int Fibonacci(int n)
{
int i;
int x,y,z;
for( i=1; i<=n; i++ )
{
if( i==1 )
{
x = 1;
printf("%d ",x);
}
else if( i==2 )
{
y = 1;
printf("%d ",y);
}
else
{
z = x+y;
x = y;
y = z;
printf("%d ",z);
}
}
putchar('\n');
}
int main()
{
int n;
scanf("%d",&n);
Fibonacci(n);
return 0;
}