Sunday, August 4, 2013

C Programming- The Sum

You are starting to learn c programming language. you want to do something with it.
Why don't you start by making a sum program.


first look at the program. the comment after //.... is for explain to you.

you just only write the program and run it without the comment after //...




// symbol and the line in every line is called comment. A good programmer should make a habit of writing comment.So that another programmer can easily understand his/her program.







Now first of all why we use int before main function? because we use integer type data in the function. so we have to write the data type name. For integer data type we have to write int.



A question has just arrived in your head ... what types of data are in the c programming language??

there are 4 types of data as..

1.int

2.double

3.float

4.char

we will work these types of data later.

In function we declared two integer, You may give any name u want, But try to name something logical. that will help another programmer to read your code.

then we declare sum.dont forget to give ";" symbol.

then we give any value to this integer data type.again dont forget to give ";" symbol.

then in sum we declare sum is equals to the sum of integer one and integer two.





Now in printf you can write anything as "your sum is %d" / "the total %d"/ '''the value %d'' anything you want. But %d means the result will be integer type data. and if you do not write %d the computer can not show you the integer type sum.





==>i have told you about double,float. these are used for decimal sum. if you use double instead of int you have to use %f instead of %d. If you use float instead of int you have to use %lf instead of %d. float is used for taking more number after decimal like 1.4546. and double is used for only two numbers after decimal like 1.45

write return 0 as your program does not return any value. you will know it more after doing some program. and there is no alternative of practicing. <==






Now problem for you. do the subtraction,multiplication and division program. take a look at my program. then do it.

***hint: you can use  -, *, /  symbol in the place of +for subtraction,multiplication and division.

C Programming- The First Program

Now I am going to write my first program in c programming language.

First of all open codebolcks. Then click File-->New-->empty file. At first save by ctrl+s. Give a name.I give it first_program.then type
#include <stdio.h>
this is the header file of c program. Remember to write this in the first.

==>Now this is enough for you to know about header file. I will explain it to you later, why i have written it. By doing this you will get into programming steps by steps. Now just believe me, and do what i am saying.

secondly type
main ()
this is called main function. In c programming language every thing you need to write in function. you have to write logic in the function. Then it will process. Function can be different type int main() , void main () ... i will discuss it later.

thirdly type
{
    
      }
In the middle of {} you have to write your logic/code/order/instruction. i use different word so that you can get it easily. after getting the c programming language you will learn about yourself. I just want to give you the very beginning concept.

fourthly type
printf("I am learning");

printf is a library function. There are many library functions for different benefits. Printf library function will print anything " " you write between this double quotation.

the program will look like



Now click "build"



If it shows process terminited with status 0,
o errors,0 warnings.    Then you program is correct.
(congratulations you can write a program :) )


Again click "build" then click "run"
now a black screen will appear.and u see the line
I am learning (what u have written between " " the double quotation.



 If it shows error when you click "Build"



try to find out the mistake, and build and run again.
Remember to be a good programmer is not easy. You need passion. So don't give up hope. Just hook up. You will be succeeded .



C programming- something for the starter

If you are willing to learn c programming language, you may start from here. i can not teach you 100% c programming language but i can give you some example. You must have to write the codes in codeblocks. If you do this you might get a general concept about c programming language.

First of all u need not to download "codeblocks". Just run the codeblocks (you may choose different c platforms, but i am writing it on codeblocks).

One word is very important in c programming language. To be a programmer; you have to program. You have to code. You may know what is program and how it can be written. But a programmer means a lot more. A programmer has to create , a programmer has to find, A programmer has to change. So unless you don't practice it,you will not get it. this is very easy.

Try programming as a passion, you will love it. And when you love it, nobody can stop you. Happy programming. :)