C language introductory content

Getting started with programming

The core idea of ​​the program design: the computer is fast, very suitable for calculation and logical judgment work. So the point of program design is to divide the work that needs to be done by the computer into several steps, and then let the computer execute them in turn. Pay attention to the word "sequential" here, there is a sequence between steps.

1.1 Arithmetic expressions (basic knowledge)

  • The two most basic functions scanf (used to input some data from the keyboard) printf (used to output some data)
  • The result of shaping and division will be rounded off the decimal part.
  • Use %d for shaping output and %f for floating-point output. You can use %._f to limit the number of decimal places.
  • For operations involving floating-point numbers, the results are all floating-point numbers.
  • The mathematical function sqrt(x) means calculating the arithmetic square root of x. If the mathematical function is used, the header file math.h must be included at the beginning of the program
  • The meaning of uppercase and lowercase letters in the C language is different.

Practice program

1. Calculate and output the value of 1+2
Answer:

#include<stdio.h>
int main ()
{
    
    
	printf("%d\n",1+2);
	return 0;
}

2. Calculate and output the value of 8/5, keeping 1 decimal place.
Answer:

#include<stdio.h>
int main ()
{
    
    
	printf("%.1f\n",8.0/5.0);
	return 0;
}

3. Complicated expression calculation (1+2*radix 3/(5-0.1) results with 8 decimal places)
Answer:

#include<stdio.h>
#include<math.h>
int main ()
{
    
    
	printf("%.8f\n",1+2*sqrt(3)/(5-0.1));
	return 0;
}

Guess you like

Origin blog.csdn.net/ABded/article/details/103338178