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.

No comments:

Post a Comment