C Quick Start series (3) and c Quick Start Series

Source: Internet
Author: User

C Quick Start series (3) and c Quick Start Series

C Quick Start series (3)


Structured Programming


----------------------------------- For reprinting, please indicate the source: coder-pig


This section introduces:

In the previous study, we had an understanding of the basic syntax of the C language, which can be understood as a word for the moment;

What we need to do now is to learn the syntax, that is, the algorithm, that is, to form a basic program!

In this section, we will learn the input and output in the C language and the three structures of the Program (sequence, selection, and cyclic structure)



This section describes the road map:



Body:


1. Character Input/Output Functions



2. format input/output functions

Different from the input and output of a single character, we need to use the printf () and scanf () functions,

Include the header file in the source file. # include <stdio. h> is the abbreviation of standard input and output, and h is the abbreviation of header.

You can write it as follows: # include "stdio. h" or # include <stdio. h>.


Format output function printf ()

What is format output: it refers to the standard output that you want to output, for example, keep 2 decimal places



Ps: There are many modifiers and format characters, which are not easy to grasp at the beginning. We recommend you write your own programs to verify and understand their functions. If you write more, you will get it!


Format input function: scanf ()

Format input, same as above, but transfers data from the keyboard to a memory space!

Full use of scanf:



If you look at the image or you still have some questions, let's demonstrate the use of scanf.

Scanf code Demonstration:

/* This Code demonstrates the use of scanf. Pay special attention to the third point. Do not add spaces, commas, and other symbols in scanf. Otherwise, you need to write them in the format when entering the code, otherwise it will cause an inexplicable problem */# include <stdio. h> int main () {int a, B, c; // 1. normal scanf usage scanf ("% d", & a, & B, & c ); printf ("a = % d B = % d c = % d \ n", a, B, c); // 2. use the * blocker to skip a certain input value scanf ("% 3d % * 2d % 2d % 3d", & a, & B, & c ); printf ("a = % d B = % d c = % d \ n", a, B, c); // 3. it is best not to write commas and spaces in scanf. Otherwise, you must write scanf ("% d, % d, % d", &, & B, & c); printf ("a = % d B = % d c = % d \ n", a, B, c); return 0 ;}

Running result:





3. Three basic program structures: Use of Sequence Structure and judgment structure if:





Determine the structure switch usage:





3. Loop Structure:



4. process jump control statement:

BreakStatement: it can only be used in loop statements and switches to jump out of the switch or out of the loop. In a multi-tier loop, only one loop exists!

ContinueStatement: skip the rest of the loop body and directly enter the next loop.


* GotoStatement: Try not to use it, because it is an unconditional transfer statement. A Random jump will make the program layers unclear and cause trouble for people who read the code!


For the sample code, see the download link provided later!




Section:

① Concept of Input and Output

② Single Character Input and Output Functions getchar () and putchar ()

③ Formatted input/output functions scanf () and printf ()

④ The example of a bank ATM leads to the judgment structure: if, if-else, if-else

⑤ Use of switch statements

6. Loop Structure: while and do-while; for loops; nested loops. Avoid endless loops!

7. process jump control statement: break and continue;


Download the learning materials in this section:







How to get started with C language

To get started, you just need to know the data type, several Syntax structures, and C language writing formats. Others mainly depend on your own thinking (that is, the algorithm), and user-defined functions.

How to get started with a C Language

Many people have no idea how to learn C language. They often ask me the same question: how to learn C language? I am a teacher and have been developing programs for many years. Like many people who have just started, the first computer language to learn is C language. After years of development, I have deeply realized how important C language is to a program designer. If you do not understand C language, it is almost ridiculous to write the underlying program, you want to write excellent and efficient programs. Why is C language so important? First, the C language syntax structure is very concise and exquisite, and the program written is also very efficient and easy to describe the algorithm. Most programmers are willing to use the C language to describe the algorithm itself, if you want to make some achievements in programming, you must learn it. Second, the C language allows you to go deep into the underlying system. Which of the operating systems you know is not written in the C language? All windows, Unix, Linux, Mac, OS/2 are inside and outside. If you do not understand C language, how can you go deep into these operating systems? Let alone write their kernel programs. Third: many new languages are derived from C, C ++, Java, C #, J #, perl... which one is not? After mastering the C language, you can master many languages. After simple learning, you can use these new languages for development, once again, the C language is an important foundation for programming. Another point: Even if you are recruiting programmers and taking tests in C language, you must master the C language if you want to join the it industry. So how to learn C language? 1: to learn how to do things well, we must first introduce several essential things for learning C language: A development environment, such as turbo C 2.0, which once occupied more than half of the development programs in the DOS era. However, in the windows era, it is difficult to use turbo C. It is difficult to edit the program and drag and drop the program. In addition, the function variable auto-sensing function is not available, and it is not convenient to query reference materials. We recommend that you use Visual C ++. Although this is a big part, once it is installed, it is very convenient to use. A learning tutorial, now the C language teaching materials such as Ox hair, but we recommend that you use "C language programming" Tan haoqiang editor of the second edition of Tsinghua University Press, this book is very suitable for beginners, And the content is also very refined. In addition, there are a lot of auxiliary learning software. After all, it is now in the Window era. Learning Software is as old as learning. I would like to recommend an integrated learning environment (C Language), which provides excellent knowledge points and routine explanations, as well as a test environment for question libraries. It is said that there are thousands of questions, there is even a windows trubo C. Beginners can practice programming without having to install other compilers. It is very suitable for beginners. There is also a "C Language Learning System" software, but it is just a question bank system. If you think the question is not enough, you can try it. 2: What is the best way to learn computer languages in Sunflower collections? Answer: Read the program. That's right. Reading a program is the fastest and best way to get started with C language. Like me, now I want to learn other languages such as J # And C #, instead of reading books one by one, but learning their routines. Of course, for beginners who have never learned any computer language, it is best to read the tutorial first. After learning each chapter, you must carefully understand all the concepts of this chapter, then let alone all the routines mentioned in this chapter, and then carefully study the program until each line understands, and then find a few programming questions, preferably similar or the same as the routine, if you try to write a program that you already understand, you can write a program that is the same as it. It is definitely not necessarily true. If you don't believe it, just give it a try, if you can't write it out, don't worry. Go back and study the routine again, think about why you can't write it out, and then write the program again and again until you get it done. Congratulations, you are getting started. 3: the highest level of writing programs at peak is to master various methods (data structures) for solving problems and methods (algorithms ). Is writing the underlying program a good programmer? Also, writing the underlying program is nothing more than mastering the hardware structure. Besides, the hardware and hardware are not the same. We need to write a driver for a chip ...... the rest is full>

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.