Header Ads

Header ADS

Learning To Program - Bing A Better Programmer (Episode - 2)

 Before learning C programming we need to know how a computer works. The computer works in the same way as the human brain works. For example, after we see something with our eyes or hear with our ears, only our brain can think about it. Then when the brain reaches a decision, we execute the brain's decision with our hands or feet.


Now let's look at the matter with the eyes of a computer. Seeing something with the eyes or hearing something with the ears means giving input. And the brain's decision-making is processing. And solving the work with hands and feet is our output. So, any programming language starting from C and even everything in the world follows this formula.

Input -> Processing-> output!

What programming language is needed?


I don't know how computers work. But why programming language?


A programming language is a language through which a computer is instructed to operate. It is surprising to know that the fact is that computers do not understand anything except 0 and 1. So should the computer use all instructions 0 and 1? But then writing the program will be very complicated.


Hopefully, initially, programs were written using only 0 and 1, but later each instruction was given a metaphorical name (eg ADD, SUB, etc) to get rid of this complexity. It is called assembly language. Also, software called Assembler is developed which converts symbolic instructions into automatic machine language.

But this assembly language also has problems. Only people who know a lot about machines can write programs here. So how about me or you?


For our convenience, developers slowly discover some high-level languages like C, C++, Java, etc. to run without knowing so many details about our machine.

C program structure

C is a mid-level programming language. Its main part is basically three.


1. header file.


2. main() function


3. Others function.

main()

{

            // C is a case-sensitive programming language

}

A C program consists of one or more functions. Every C program has a user-defined function called main(). A small C program can be written as:



It is better to say that if you write Main() instead of main() then your compiler (in which the C program will be written) will give an error. Again in some places, you have to put a semicolon. A comma instead of a semicolon or no semicolon will give an error.


For example, you must put a semicolon at the end of the instruction you want to live inside the main() function. Let's say you want to print a line. In that case, you need to use the printf() function.


As mentioned earlier, a header file has to be declared in a C program. In the process of declaring the header file,


#include<header file>


We learned a lot. Now start the programming part by running a program. You can start C programming with any compiler. Turbo C, Codeblocks anything. If you don't have Codeblock software on your computer, you can easily download it from the net.

You can download and install the binary release by going to this address.

http://www.codeblocks.org/downloads

When Code-Blocks is installed, when you open a new project, you will see a window like this.

From there, if you click on the Console application, write the name of the program, and save the location, then a new window will appear to write the program.


Or you can open a new project from a file.


Computers understand nothing but 0 and 1!


Now we will write a program. The first C program we wrote!


#include<studio.h>

main()

{

printf(“I am a C programmer”);

)


If you run the program by typing it and clicking on the green button above, you will see a separate screen—

I am a C programmer.

This way you can easily write your first program.

Now suppose you want to write two lines. So what do you do? very simple Writing print () twice will do it.


#include<studio.h>

main()

{

printf(“I am a C programmer”);

printf(“I am a C programmer”);

)


 

I am a C programmer who will output two lines like this.

but you want

I am a C programmer

I am a C programmer.


In that case, you have to painstakingly add \n to the end of the first line. \n means new line.


#include<studio.h>

main()

{

printf(“I am a C program\n”);

printf(“I am a C programmer”);

)


Well, adding \n before the second line would get you the output you want? Do not try to practice yourself… 😀

At first, the lines will be typed again and again without copying and pasting. And in the next part, I am bringing some more general topics of C programming. I am saying one thing again, I will try to give some very basic, even basic ideas of C programming through a few episodes. I know you can't learn programming through this. But I also know that if you read all the episodes, maybe you will have some interest in learning programming. And if you are interested, in how quickly you will learn to program, you will not understand. 😀


Happy Programming.. 😀

No comments

Featured Post

The Future Space Tourism - 2050

 In the next three decades, human beings will enter the realm of space like never before. This is partly due to the way that public interest...

Popular Post

Powered by Blogger.