Thursday, September 26, 2013

Second Program : Adding Two Numbers

Hey guys now that we know how to print something on the screen lets start with something more interesting ... You  can make your own calculator using C ,Lets see how
first we use the inbuilt libraries for standard input output that is stdio.h

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sum;   // Variables for storing that input and output
printf("\n Enter the first number: "); // Print Enter the first number on screen
scanf("%d",&a); //Read the input using scanf (we will discuss about scanf in next post) & store it in a
printf("\n Enter the second number: "); // Print Enter second number
scanf("%d",&b);// Store second value in b
sum=a+b; // Calculate sum of a and b and put in sum
printf("\n Sum Is %d",sum); // Print the sum on screen
getch(); // Wait till any key is pressed
}

Saturday, September 21, 2013

Starting Things Practically

First we need a C compiler installed on our machine if its an linux system you can open the terminal and check by typing the command below

cc

if you are a windows guy then follow the steps to download the Dev C++ from Bloodshed


Go to the url below and click on the link show the pic(Highlighted with red box around it)

http://www.bloodshed.net/dev/devcpp.html




After clicking it should start the download

........................................ After the download is completed

Run the executable  in the choose components  click on remove previous versions if you have already .

After the setup is finished start the Dev C ++ and keep clicking next

Then it should look like this





Then go to File --- New --- Source File   And click on it or directly pres ctrl+n

then type the following code

#include<stdio.h>
#include<conio.h>
int main()
{
printf("Hello World");
getch();
}

Then click  on Execute Click On Compile
after the program has been compiled
Go to Exexute and click on Run







Congratulations You Have Successfully Written Your First C Program

Wednesday, September 18, 2013

Dissecting The Program

The program in the last post is very simple , consisting  just few lines of C code . But it is very important to understand this as it serves as the foundation for larger programs. As they say " Journey Of A Thousand Miles Begins With A Single Step ".
Let's look at the program line by line .


#include<stdio.h>

The Header of the program is very necessary if you want to use the printf statement . Without this line the printf statement won't work.  We will  look at it in detail later when we are writing our own libraries. As of now all we need to know is the printf statement is declared in the stdio.h library and stdio.h stands for Standard Input Output Header. Some other libraries are conio.h , math.h (Just remember the names for now)

 void main ()     
    {
    }

This is the Main part of the program . If you are given a task to do something you need to know how to start the task right?? Similarly main is used so that the computer can know from where it has to start executing the program. The computer executes whatever is inside the Main function`s body.The body of the main function is defined by the curly braces {  } .
printf ("Hello World");

This is the line that prints Hello World onto the screen . We will be using this function more than any other function (Trust Me) 

So thats it lets get started with a few practical aspects from the next post .








Monday, September 16, 2013

A Very Simple C Program

Now lets take a look  at a very small and simple C program.
Compare this to the structure we have discussed before so that it will be easier to understand , as all C programs will follow the same structure.
#include <stdio.h>              // This is the header of the program
void main ()                       // The main function of the program
{
printf ("Hello World");      /*A simple inbuilt function to print things onto the screen. */
}

UPDATE !!!!

Hi Everyone
We Will Resume The Normal Operation Of The Blog Soon. So Please Keep Checking Regularly
Please Do Comment If You Find The Blog Helpful.