9.1
#include <stdio.h>
double min (double x, double y);
int main(void)
{
double x,y;
printf("Please enter two numbers:\n");
while (scanf("%f %f",&x,&y)==2)
{
printf("The smaller number is %.2f.\n",min(x,y));
printf("Please enter next two numbers(q two exit):\n");
}
printf("BYE!!!\n");
return 0;
}
double min (double x, double y)
{
return x<y?x:y;
}
9.3
#include <stdio.h>
void chline ( char ch, int i, int j);
int main(void)
{
int i=0;
int j=0;
char ch;
printf("please enter the char you want to print: ");
ch=getchar();
printf("please enter i,j:");
scanf("%d %d",&i,&j);
chline(ch,i,j);
return 0;
}
void chline ( char ch, int i, int j)
{
for (int col1=0;col1<i;col1++)
{
for (int col2=0;col2<j;col2++)
putchar(ch);
putchar('\n');
}
}
9.4
#include <stdio.h>
double reciprocal ( double a, double b);
int main(void)
{
int x,y;
printf("Please enter two numbers:\n");
while(scanf("%d %d",&x,&y)==2)
{
printf("Harmonic mean:%lf .\n",reciprocal(x,y));
printf("Please enter next two numbers:\n");
}
printf("BYE!!!!");
return 0;
}
double reciprocal ( double a, double b)
{
double rec;
a=1/a;
b=1/b;
rec=1/((a+b)/2);
return rec;
}
9.5
#include <stdio.h>
double large_of (double a, double b );
int main(void)
{
double x,y;
printf("Please enter two numbers:\n");
while(scanf("%lf %lf",&x,&y)==2)
{
printf("Now x=y=%lf.\n",large_of(x,y));
printf("Please enter next two numbers:\n");
}
printf("BYE!!!!");
return 0;
}
double large_of ( double a, double b)
{
return a>b?a:b;
}
9.6
#include <stdio.h>
int main(void)
{
int chars;
printf ("Please enter some words:\n");
while ((chars=getchar())!=EOF)
{
if(chars>='a'&&chars<='z')
printf("You enter the '%c',It is the position of %d .\n",chars,chars-'a'+1);
else if(chars>='A'&&chars<='Z')
printf("You enter the '%c',It is the position of %d .\n",chars,chars-'A'+1);
else printf("You enter the character %c ,but it is not a letter .\n",chars);
}
}
#include <stdio.h>
double min (double x, double y);
int main(void)
{
double x,y;
printf("Please enter two numbers:\n");
while (scanf("%f %f",&x,&y)==2)
{
printf("The smaller number is %.2f.\n",min(x,y));
printf("Please enter next two numbers(q two exit):\n");
}
printf("BYE!!!\n");
return 0;
}
double min (double x, double y)
{
return x<y?x:y;
}
9.3
#include <stdio.h>
void chline ( char ch, int i, int j);
int main(void)
{
int i=0;
int j=0;
char ch;
printf("please enter the char you want to print: ");
ch=getchar();
printf("please enter i,j:");
scanf("%d %d",&i,&j);
chline(ch,i,j);
return 0;
}
void chline ( char ch, int i, int j)
{
for (int col1=0;col1<i;col1++)
{
for (int col2=0;col2<j;col2++)
putchar(ch);
putchar('\n');
}
}
9.4
#include <stdio.h>
double reciprocal ( double a, double b);
int main(void)
{
int x,y;
printf("Please enter two numbers:\n");
while(scanf("%d %d",&x,&y)==2)
{
printf("Harmonic mean:%lf .\n",reciprocal(x,y));
printf("Please enter next two numbers:\n");
}
printf("BYE!!!!");
return 0;
}
double reciprocal ( double a, double b)
{
double rec;
a=1/a;
b=1/b;
rec=1/((a+b)/2);
return rec;
}
9.5
#include <stdio.h>
double large_of (double a, double b );
int main(void)
{
double x,y;
printf("Please enter two numbers:\n");
while(scanf("%lf %lf",&x,&y)==2)
{
printf("Now x=y=%lf.\n",large_of(x,y));
printf("Please enter next two numbers:\n");
}
printf("BYE!!!!");
return 0;
}
double large_of ( double a, double b)
{
return a>b?a:b;
}
9.6
#include <stdio.h>
int main(void)
{
int chars;
printf ("Please enter some words:\n");
while ((chars=getchar())!=EOF)
{
if(chars>='a'&&chars<='z')
printf("You enter the '%c',It is the position of %d .\n",chars,chars-'a'+1);
else if(chars>='A'&&chars<='Z')
printf("You enter the '%c',It is the position of %d .\n",chars,chars-'A'+1);
else printf("You enter the character %c ,but it is not a letter .\n",chars);
}
}