The idea of programming might sound like a frightening task, but don’t worry. We designed this blog so that you can get your feet wet without stepping into the deeper complexities of the programming.
This site is dedicated to all those people who want to learn the most basic but important Programming Language'C Programming'.
If done step wise C language is easy and fun to learn.
So lets get started.
Start reading from the First Post to understand C programming.You may read a desired topic from the labels.
One of the best methods to learn any programming language is to observe as much as programs you can , try editing them.
You can take a look at the various programs on this blog and feel free to ask if any doubts in with them.
Press Ctrl+D to add this page to your Favourites/Bookmarks for further reference.
Note:Your comments,queries and suggestions are welcome.Feel free to post them in the the comment boxes available after every post.

If you are interested in learning PHP, to create your own website or to spice up your existing website;here is the Best Tutorial available for PHP

Search C Programs,Compilers,Seminars ,Projects,etc.

Monday, August 29, 2011

Calculating the average of two numbers using C++

Though this site aims at understanding C language, I am writing a program for you in C++, to have a general idea about C++ too.
A program in C++,to calculate the average of two numbers, which are entered by the keyboard while the execution of the program.
Try to understand the program;

#include < iostream >
using namespace std;
int main()
    float num1,num2,average,sum;
    cout << "Enter the first number:";
    cin >> num1;
    cout << "Enter the second number:";
    cin >> num2;
    cout << "The sum of the two numbers is:"<< sum<<"\n"<<"The average of the two numbers is:" << average;


The new file header used here in this C++ program is the #include. By this , we are asking the preprocessor to add the contents of the iostream file to our program.

The program is written in the main() function , just like in C.

The variables are defined as float in the same manner.

Here in C++ we use cout and cin operators for output and input respectively. These are parallel to the printf and scanf in C.
In the last cout statement the output is cascaded using the cout operator.which is new in the C++ .

As the main() function is integer type , it returns a zero value which is written as return(0)