#include<stdio.h>
double min(double x, double y);
int main(void)
{
double a, b;
printf("Please enter two double numbers (q to quit):");
while ((scanf("%lf %lf", &a, &b)) == 2)
{
printf("The min number between %lf and %lf is %lf.\n", a, b, min(a, b));
printf("Enter again (q to quit):");
}
printf("Bye!\n");
return 0;
}
double min(double x, double y)
{
double min = x;
if (y < x)
min = y;
return min;
}
2
#include<stdio.h>
void chline(char ch, int i, int j);
int main(void)
{
char ch;
int i, j;
printf("Please enter a character , cols and rows (q to quit):\n");
while ((scanf("%c %d %d", &ch, &i, &j) == 3))
{
chline(ch, i, j);
printf("Please enter again (q to quit):\n");
}
printf("Bye!\n");
return 0;
}
void chline(char ch, int num1, int num2)
{
int i, j;
for (j = 1; j <= num2; j++)
{
for (i = 1; i <=num1; i++)
{
putchar(ch);
}
printf("\n");
}
}
3
#include<stdio.h>
void chline(char ch, int i, int j);
int main(void)
{
char ch;
int i, j;
printf("Please enter a character , cols and rows (q to quit):\n");
while ((scanf("%c %d %d", &ch, &i, &j) == 3))
{
chline(ch, i, j);
printf("Please enter again (q to quit):\n");
}
printf("Bye!\n");
return 0;
}
void chline(char ch, int num1, int num2)
{
int i, j;
for (j = 1; j <= num2; j++)
{
for (i = 1; i <=num1; i++)
{
putchar(ch);
}
printf("\n");
}
}
#include<stdio.h>
void larger_of(double x, double y);
int main(void)
{
double x, y;
printf("请输入两个浮点数(q to quit):\n");
while ((scanf("%lf %lf", &x, &y)) == 2)
{
larger_of(x, y);
printf("Please enter again (q to quit):\n");
}
printf("Bye!\n");
return 0;
}
void larger_of(double x, double y)
{
double max = x;
printf("Original x = %lf and y = %lf.\n", x, y);
if (y >= x)
{
max = y;
x = max;
}
else
y = max;
printf("Now x = %lf and y = %lf.\n", x, y);
}
6
#include<stdio.h>
void min_to_max(double *x, double *y, double *z);
int main(void)
{
double x, y, z;
printf("Please enter three double numbers (q to quit):\n");
while ((scanf("%lf %lf %lf", &x, &y, &z)) == 3)
{
min_to_max(&x, &y, &z);
printf("Please enter again (q to quit):\n");
}
printf("Done!\n");
return 0;
}
void min_to_max(double *x, double *y, double *z)
{
double min = *x;
double middle = *y;
double max = *z;
if (min >= middle && min >= max)
{
max = *x;
if (middle >= max)
{
min = *z;
}
else
{
min = *y;
middle = *z;
}
}
else if (middle >= min && middle >= max)
{
max = *y;
if (min >= max)
{
middle = *x;
min = *z;
}
else
middle = *z;
}
else if (max >= middle && max >= min)
{
if (min >= middle)
{
min = *y;
middle = *x;
}
}
printf("min = %lf, middle = %lf, max = %lf\n", min, middle, max);
}
7
#include<stdio.h>
#include<ctype.h>
int jug_alpha(char ch);
int main(void)
{
char ch;
while ((ch = getchar()) != EOF)
{
printf("%d", jug_alpha(ch));
}
return 0;
}
int jug_alpha(char ch)
{
int back;
if (isalpha(ch))
{
if (islower(ch))
back = ch - 96;
if (isupper(ch))
back = ch - 64;
}
else
back = -1;
return back;
}
8
#include<stdio.h>
double power(double n, int p);
int main(void)
{
double x, xpow;
int exp;
printf("Enter a number and the positive integer power");
printf(" to which\nthe number will be raised. Enter q");
printf(" to quit.\n");
while (scanf("%lf%d", &x, &exp) == 2)
{
xpow = power(x, exp);
printf("%.3g to the power %d is %.5g\n", x, exp, xpow);
printf("Enter next pair of numbers or q to quit.\n");
}
printf("Hope you enjoyed this power trip -- bye!\n");
return 0;
}
double power(double n , int p)
{
double pow = 1, temp = 1;
int i;
if (n == 0)
{
if (p == 0)
printf("0 power of 0 is undefined. So it is 1.\n");
else
pow = 0.0;
}
else if (p == 0)
pow = 1.0;
else if (p > 0)
{
for (i = 1; i <= p; i++)
pow *= n;
}
else
{
for(i = 1; i <= (-p); i++)
temp *= n;
pow = 1.0 / temp;
}
return pow;
}
1#include&amp;amp;lt;stdio.h&amp;amp;gt;double min(double x, double y);int main(void){ double a, b; printf(&amp;quot;Please enter two double numbers (q to quit):&amp;quot;); while ((scanf(&amp;quot;%lf %lf&