Calculation of XDOJ quality

//It is known that the specific gravity of iron is 7.86 (g/cubic centimeter) and that of gold is 19.3 (g/cubic centimeter).
//Write a program to calculate the masses of iron balls and gold balls with given diameters, assuming PI=3.1415926
//Input instructions:
//Enter two integers, representing the diameters of iron balls and gold balls respectively (units are millimeters) )
//Output description:
//Output two floating point numbers, representing the mass of the iron ball and the gold ball respectively (unit is grams), retain 3 decimal places after the decimal point, separate the two floating point numbers with spaces //Input
sample :
//100 100
//Output sample:
//4115.486 10105.456
//Prompt
//Use scanf to input and printf to output. The format control character that retains 3 decimal places is %.3f.

#include<stdio.h>
int main()
{
    
    
	int d1,d2;
	float m1,m2,PI=3.1415926;
	scanf("%d %d",&d1,&d2);
	m1=(4.0/3)*(d1/20)*(d1/20)*(d1/20)*PI*7.86;
	m2=(4.0/3)*(d2/20)*(d2/20)*(d2/20)*PI*19.3;
	printf("%.3f %.3f\n",m1,m2);
	printf("%d %d",d1,d2);
	return 0;
}

In fact, it is also a very simple question. I used this question today to do the start of program for my juniors. The
overall meaning is very simple. As a senior, let me talk about my experience and knowledge in the first program.
First of all, it is a framework of functions, which is your The body and bones, a process that accompanies this life, will also accompany this death.

#include<stdio.h>
int main()
{
    
    
  ......
  return 0;
}

Note :

1. Be sure to understand Chinese and English. Novices often make mistakes when reading Chinese characters (it can also be seen from the encoding method, such as English ;and Chinese )
[ASCII only supports English, all 8-bit DBCS supports English and Chinese, But Chinese requires two bytes (16 bits)]
2. You must add it at the end of a statement ;, otherwise what is waiting for you is [Error] expected ';' before 'return'
3. Distinguish that '/" is an integer but is like 4.0/5 Will be automatically compiled into floating point division

おすすめ

転載: blog.csdn.net/weixin_50925658/article/details/120589653