Notes-C language-first section in printf scanf

Source: Internet
Author: User
Tags integer numbers

The variable must be declared before//using the variable!

// Declare the syntax format of the variable:

// data type variable name = initial value ;

//Name rules for variable names

/**

* 1. Variable names can only be composed of letters, numbers, underscores, and numbers cannot begin.

2. Variable names cannot be named repeatedly

3. Variable name cannot be duplicate with system reserved word

4, variable names must be known as the name of the meaning

*/

3a A3 _a A_ a_b float char return numberofstudent

Typeofhero Herotype

// Common data types are char, short,int , long,float single-precision floating-point, Double Dual-precision floating-point type.

the// variable represents a piece of storage area that can change during a program's run.

//The following line of code means : declare a character variable c, theinitial value is ' a '

char c = ' A ';

c = ' B ';

// variables of the same data type can be placed on the same line to declare, separated by commas.

int a = 3, B = 5, d = 10;

A = 10;

//

float F = 3.25;

f = 4.5;

/*

Exchange values for two integer variables

int a = ten, B = 8, temp = 0;

assigns the value of a to C

temp = A;

Assign the value of B to a

A = b;

Assign the value of C to Band complete the interchange.

b = temp;

*/

int a = 10;

//

printf ("Hello world!\\%% 123%d,%c,%f\n", A + =, ' a ', 3.14);

printf ("%-4d\n", a);

//

//

//

//

1.

int number1 = 1, number2 = 4;

//

float result = 0.0;

//

result = (float) number1/number2 * 100;

//

printf ("1 accounted for 4 of %.0f%%\n", result);

//

2.

Analysis Ideas :

//    /**

* 1, how to get a 0.25 decimal, when declaring a variable, declare one of the variables as a floating-point type

2,0.25 How to become the last print , multiplied by

3, the value after the decimal point all do not, the placeholder is %.0f

4.How to print a percent semicolon, enter two % in the format string

//     */

int number3 = 1;

Float NUMBER4 = 4.0, result1 = 0.0;

//

RESULT1 = number3/number4 * 100;

//

printf ("1 of 4 %.0f%%", RESULT1);

int a = 0,b = 0;

char c = ' 0 ';

//

printf (" Please enter two integers, one character :");

//

scanf ("%d%d%c", &a, &b, &c);//and

//

printf ("Number is%d,%d, char is%c", A, B, c);

// require the user to enter two integers, calculate the number of two inputs, and output the result.

//1, declare two variables to receive, the number of users input from the console, and then declare a variable, to save the sum of two numbers.

int number1 = 0, number2 = 0, result = 0;

//2, reminding the user to enter two integer digits

printf (" Please enter two integer numbers :");

//3, receiving user-entered numbers

scanf ("%d%d", &number1, &number2);

//4, calculation

result = Number1 + number2;

//5, output calculation results

printf (" you have entered the number of two and is :%d", result);    

return 0;

}

Notes-C language-first section in printf scanf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.