c language programming tutorial
1, any language needs a suitable compiler, first we download a suitable compiler for the C language, today we explain the C language compiler for CodeBlocks, the compiler is clear and easy to understand.
2, first double-click to open the compiler, enter the login selection interface, we choose to create a new project.
3, and then enter the selection interface, because we want to achieve simple C programming, so now give priority to select “Consoleapplication”, and then double-click to enter.
4, after entering is the prompt interface, we choose “Next” next. Then select C++ language, C++ language is an upgraded version of C language, and then click “Next”.
5, select the name of the creation. Then the file is placed in the location, the location as good as possible, it will be convenient to learn later, and then click Next.
6, and finally click on the left side of the “main.cpp” will appear in the programming interface, and then delete the existing, you can realize our code programming.
Getting Started with C (Basics)
C is a high-level programming language widely used in the development of system and application software. It was developed by Dennis Ritchie of Bell Labs in the early 1970s as a structured, process-oriented language.C is characterized by simplicity, efficiency, and flexibility, making it one of the most important programming languages in the field of computer science.
Two, the basics of C language
1. Data types: C language provides a variety of data types, including integer, floating-point, character type and so on. In C, we need to declare the data type of a variable before using it.
2. Variables and Constants: Variables in C are used to store data and constants are immutable values. Before using a variable, we need to declare its type and name.
3. Operators: C language provides a variety of operators including arithmetic operators, relational operators, logical operators, and so on. Operators are used to perform various mathematical and logical operations.
4. Control Statements: Control statements in C are used to control the execution process of the program. Common control statements include conditional statements, loops and jump statements.
Three, the operation of the C language steps
1. Installation of the compiler: First of all, we need to install the C language compiler on the computer. Commonly used C compilers are GCC, Clang and so on.
2. Write code: Use a text editor to create a new C source file and write code.C source files have .c extension.
3. Compile the code: Open a command line window, go to the directory where you saved the source file, and use a compiler to compile the source file into an executable. For example, using the GCC compiler, you can execute the following command: gcc-oprogramprogram.c
4. Run the program: Enter the name of the executable file in the command line window to run the program. For example, type program to run an executable named program.
4. Example of Getting Started in C
The following is a simple example of a C program to compute the sum of two integers:
“`c
include
intmain(){
intnum1,num2,sum;
printf (“Please enter two integers:”);
scanf(“%d%d”,
sum=num1+num2;
printf(“The sum of the two integers is: %d\n”,sum);
return0;
}
“`
In this sample program, we first use the `include` statement, which is used to include the standard input/output library. Then, we define three variables `num1`, `num2`, and `sum`, which are used to store two integers and their sum, respectively. Next, the `printf` function is used to output a prompt message and the `scanf` function is used to receive two integers from the user. Then, add the two integers and store the result in the `sum` variable. Finally, use the `printf` function to output the result of the calculation.
The basic steps in C programming are?
Step 1:
Analyze the problem.
Step 2:
Draw the basic outline of the program.
Step 3:
Implement the program.
(1)
Write the program;
(2)
Test and debug the program;,(3)
Provide a printout of the data.
What are the methods of program design in C?
Programming methods:
1. Write a generalized abstract description of the problem in terms of its big picture.
2. Define variables, select functions, and determine the algorithm. Algorithm this thing is not easy to say, encountered more problems, will naturally form their own set of algorithms.
3. According to the order of the problem to solve the statements and functions in the main () stacked up.
What are the steps to follow to learn C?
Step 1: Define the goal of the program
Before you get down to writing a program, have a clear idea in your head. What you want the program to do first you need to be clear yourself about what you want to do, think about what information the program needs, what calculations and controls it will perform, and what information the program should have to report. In this step, no specific computer language is involved and the problem should be described in general terms.
Step 2: Designing the Program
After having a conceptual idea of what the program is supposed to accomplish, it is time to think about how the program will be used to accomplish it. In addition to this, it is important to decide how the data will be represented in the program (and possibly auxiliary files) and what methods will be used to process the data.
The problems encountered at the beginning of learning C are simple, with little to choose from.
Step 3: Write the code
After designing the program, you can write the code to implement it. That means translating the designed program into C. Here is where you really need to use the C language. You can write the ideas down on paper, but eventually the code has to be entered into the computer.
Program Listing 1.1 C Source Code Example
#include<stdio.h>
intmain(void)
{
intdogs;
printf(“Howmanydogsdoyouhave?\ n”);
scanf(“%d”,&dogs);
printf(“Soyouhave%ddog(s)! \n”,dogs);
return0;
}
In this step, you should add textual comments to the program you have written. The easiest way to do this is to use C’s commenting tools to add an explanation of the code in the source code.
Step 4: Compile
This next step is to compile the source code. Again, the reader is reminded that the details of compilation depend on the programming environment, and some common programming environments will be described shortly. For now, let’s start by explaining what happens with compilation from a conceptual point of view.
A compiler is a program that converts source code into executable code. Executable code is code expressed in the machine language of a computer. This language consists of instructions represented by numeric codes. As mentioned earlier, different computers use different machine language schemes.The C compiler is responsible for translating C code into a specific machine language.
In addition, the C compiler merges the source code with the code from the C library (which contains a large number of standard functions for the user to use, such as printf() and scanf()) into the final program (more precisely,
The compiler also checks the C program to see if it is valid. If the C compiler finds an error, it does not generate an executable and reports an error. Understanding the error or warning messages reported by a particular compiler is another skill for programmers to master.
Step 5: Run the Program
Traditionally, executables are runnable programs. Running a program in common environments (including Windows Command Prompt Mode, UNIX Terminal Mode, and Linux Terminal Mode) involves typing the filename of the executable, while other environments may involve running commands (e.g., VMS[2] in VAX) or some other mechanism.
For example, in the integrated development environments (IDEs) available for Windows and Macintosh, the user can edit and execute a C program in the IDE by selecting options in menus or by pressing special keys. The resulting program can be run directly in the operating system by clicking or double-clicking on a file name or icon.
Step 6: Test and debug the program
It’s a good sign that the program works, but sometimes it can run wrong. The process of finding and fixing program errors is called debugging. It is inevitable that you will make mistakes in the process of learning, and so is learning to program. Therefore, it’s a good idea to prepare yourself mentally for the fact that you will make mistakes when applying what you’ve learned to programming.
Step 7: Maintaining and Modifying the Code
After creating a program, you find that there is an error in the program or you want to extend the program’s use. For example, the program made an error when the user typed in a name beginning with Zz, came up with a better solution, wanted to add a new and better feature, or wanted to modify the program so that it would run on a different computer system, and so on.