1062 case conversion
1. Topic analysis
In this topic, we mainly investigate the use of judgment sentences, as well as the case knowledge of letters. The difference between the upper and lower case ASCII codes of a letter is 32
2. Title code
#include<stdio.h>
int main()
{
char a;
scanf("%c",&a);
if(a<='z'&&a>='a')
{
a=a-32;
}
else if(a<='Z'&&a>='A')
{
a=a+32;
}
printf("%c",a);
return 0;
}
1068 if statement 1
1. Topic analysis
In this topic, we only examine the use of choice sentences, which is relatively simple.
2. Title code
#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a>=90&&a<=100)
{
printf("A");
return 0;
}
else
printf("B");
return 0;
}
1070 if3
1. Topic analysis
In this topic, beginners are often stuck in how to compare each of the three digits. To get a three digit number, we can use three variables to store each three digit number. The three digits are separated by dividing the remaining 10 by 10. No matter what we will face in the future is three digits or several digits, the way to separate the digits of integers is to divide the rest 10 by 10.
2. Title code
#include<stdio.h>
int main()
{
int x,a,b,c,d;
scanf("%d",&x);
a=x%10;
b=x/10;
c=b%10;
d=b/10;
if (a==c&&c!=d&&a!=d) {printf("Yes");}
else if(c==d&&a!=c&&a!=d) {printf("Yes");}
else if(a==d&&a!=c&&c!=d) {printf("Yes");}
else if(a==c&d==c) {printf("No");}
else if(a!=c&&c!=d&&a!=d) {printf("No");}
return 0;
}
1071 if4
1. Topic analysis
In this topic, the first thing we need to do after we know the three sides is to judge whether these three sides can form a triangle, so we need to use judgment statements; in addition, we need to use mathematical functions when we use Helen formula to find the area, so don't forget to add math.h to the header file
2. Title code
#include<stdio.h>
#include<math.h>
int main()
{
float a,b,c,d;
scanf("%f %f %f",&a,&b,&c);
if(a+b>c&&a+c>b&&b+c>a)
{
d=(a+b+c)/2;
printf("%.2f",sqrt(d*(d-a)*(d-b)*(d-c)));
return 0;
}
else
{
printf("Not a triangle.");
return 0;
}
}
1072 switch
1. Topic analysis
This topic is mainly about the use of switch statements. When using switch statements, please don't forget to add break; remember that I didn't add it when I was learning, and then I would make mistakes. So don't forget to break the branch of switch;
2. Title code
#include<stdio.h>
#include<math.h>
int main()
{
int x;
double y;
scanf("%d",&x);
if(0<=x&&x<10)
{y=cos(x+3.0); printf("%.5lf",y);}
else if(10<=x&&x<20)
{y=cos(x+7.5)*cos(x+7.5); printf("%.5lf",y);}
else if(20<=x&&x<30)
{y=cos(x+4.0)*cos(x+4.0)*cos(x+4.0)*cos(x+4.0);
printf("%.5lf",y);}
else {printf("Not define");}
return 0;
}
1073 maximum and minimum
1. Topic analysis
This problem is mainly to find the maximum and minimum number, so, compare each number well and record the maximum and minimum number for output.
2. Title code
#include<stdio.h>
int main()
{
int a,b,c;
float t,max,min;
scanf("%d %d %d",&a,&b,&c);
if(a>b)
{t=a;min=b;}
else
{t=b;min=a;}
if(t>c)
max=t;
else
max=c;
if(min>c)
min=c;
printf("%g %g",max,min);
return 0;
}