[Introduction to C language] ZZULIOJ 1011-1015

ZZULIOJ 1011: Surface Area of ​​Cylinders

topic description

Input the base radius r and height h of the cylinder, calculate the surface area of ​​the cylinder and output it to the screen. It is required to define the pi as the following macro constant #define PI 3.14159

enter

Enter two real numbers, which are the base radius r and height h of the cylinder.

output

Output a real number, the surface area of ​​the cylinder, rounded to 2 decimal places.

sample input 

42.1 71.6

sample output 

30076.14
#include <stdio.h>#include <stdlib.h>#define PI 3.14159

int main()
{   double  r,h,s;    scanf("%lf %lf",&r,&h);    s=2*PI*r*h+2*PI*r*r;    printf("%.2lf",s);    return 0;}

ZZULIOJ 1012: Finding the Absolute Value

topic description

Finds the absolute value of a real number.

enter

Enter a real number. 

output

Output its absolute value with two decimal places

sample input 

-234.00

sample output 

234.00
#include <stdio.h>#include <stdlib.h>
int main(){
   
       double m,n;    scanf("%lf",&m);    if(m>=0)        n=m;    else        n=m*(-1);    printf("%.2f\n",n);    return 0;}

ZZULIOJ 1013: Find the distance between two points

topic description

Given the coordinates of two points A(x1, y1), B(x2, y2), calculate the distance between them.

enter

The input contains four real numbers x1, y1, x2, y2, which are separated by spaces, and the meaning is as described. where 0≤x1, x2, y1, y2≤100.

output

The output occupies one line and contains a real number d, which represents the distance between the two points A and B. Results are rounded to two decimal places.

sample input

1 1.5 2 2.5

sample output

1.41
#include <stdio.h>#include <math.h>

int main(){
   
       double x1,y1,x2,y2,d;    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);    d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));    printf("%.2f\n",d);    return 0;}

ZZULIOJ 1014: Find the Area of ​​a Triangle

topic description

 Given the three sides of a triangle, find the area of ​​the triangle.

enter

 Enter the lengths of the three sides of the triangle (real numbers), and separate the data with spaces.

output

Output the area of ​​the triangle with 2 decimal places.

sample input

2.5 4 5

sample output

4.95

hint

Heron's formula or other methods can be used.

#include <stdio.h>#include <stdlib.h>
int main(){   double x,y,z,s;    scanf("%lf %lf %lf",&x,&y,&z);    s=sqrt(x*x*y*y/4-((x*x+y*y-z*z)*(x*x+y*y-z*z))/16);    printf("%.2lf",s);    return 0;}

ZZULIOJ 1015: Calculating Time Intervals

topic description

Read in two time points represented by "hour:minute:second" and calculate the time interval in seconds.

enter

The input has two lines, and each line is a time point represented by "hour:minute:second". The test data guarantees that the second time point is later than the first time point.

output

Output an integer representing the number of seconds in the time interval.

sample input

08:00:0009:00:00

sample output

3600

hint

If there are ordinary characters in the input data, such as a colon, there should be corresponding characters in the corresponding position in the format string of the scanf function.

#include <stdio.h>#include <stdlib.h>#define PI 3.14159
int main(){   int x,y,z,a,b,c,m;    scanf("%d:%d:%d",&x,&y,&z);    scanf("%d:%d:%d",&a,&b,&c);    m=3600*a+60*b+c-3600*x-60*y-z;    printf("%d",m);    return 0;}

 

Guess you like

Origin blog.csdn.net/m0_62975468/article/details/125929809