Wednesday, June 1, 2016

Using Code::Blocks



Hi Guys , its been a long time since i have posted in this blog . I would like to revive this blog as people are interested in this. I would also like to use a different IDE called CodeBlocks . Here is the link to download the IDE
http://sourceforge.net/projects/codeblocks/files/Binaries/16.01/Windows/codeblocks-16.01mingw-setup.exe

After downloading and installing CodeBlocks here are the steps to create a project 

1) Open Codeblocks



2)Create A New Project



3) Create A Console Application



4)Click On Next



5) Select C As Language



6)Name The Project


7)Select GNC GCC Compiler



8)Empty Project



9)Add Empty File To Project



10) Name File As Main.c



11) Write A Hello World Program



12) Execute Program By Pressing Ctrl + F10


Thats It you are done creating your first CodeBlocks Project .

Thursday, December 12, 2013

Examples For Input And Output Through Programming .... Continued

Today lets look at how to read one or more variable in the same program.


#include<stdio.h>
void main()
{
int n;
float f;
printf("Enter An Integer And An Floating Number");
scanf("%d%f",&n,&f);
printf("The Entered Integer Is %d And Floating Number Is %f",n,f);

}

Friday, November 22, 2013

Examples For Input And Output Through Programming

Now lets look at few fairly simple examples. Let us read an input from user and show what the user has entered in the next line

For Integer

#include<stdio.h>
#include<conio.h>

void main()
{
int entered;
printf("Enter An Integer :")
scanf("%d",&entered);
printf("\n The Entered Integer Is %d",entered);
getch();
}
 

For Floating

#include<stdio.h>
#include<conio.h>

void main()
{
float entered;
printf("Enter An Floating Number :")
scanf("%f",&entered);
printf("\n The Entered Float Is %f",entered);
getch();
}



For Character
#include<stdio.h>
#include<conio.h>

void main()
{
char entered;
printf("Enter An Character :")
scanf("%c",&entered);
printf("\n The Entered Character Is %c",entered);
getch();
}


Try these out & also try to read two or more variables in a single scanf statement .Like reading and an integer and a floating in the same program and displaying both at once. We will look at this in the next post.....


Saturday, November 2, 2013

Input & Output Through Programming

Ok now we have some idea on how to save numbers in C . Now lets look at how we can get input data from the user and how we can give the user the output . The stdio.h gives us few functions to accomplish this task.
1. printf()
2. scanf()

The printf function allows us to print data on the screen so the user can see it while the scanf is used to get the data from the keyboard.

In Detail
 Printf ()

Syntax : printf("The Data You Want To Print :placeholder", argument list);
 Example: printf("The Sum Is %d",c)

Now lets break down the syntax for printf . The stuff within the quotes gets printed as it is . The placeholder is used in place where you want the variables to appear in the screen it can be between the the line or at the end . This is followed by the argument list that is the list of variables which will appear on the screen in place of the placeholders (Thats what placeholders are for :P ).
What are placeholders???
Relax we have already looked at them . You will understand by just looking at the example of placeholder  . Example of placeholder %d,%f ,%c, %s .

Few Examples Of printf Statements
printf("The Key You Entered Is %c ",key);
printf("The Sum Of %d + %d = %d",a,b,sum);
printf(" %f x %f = %f  \n",a,b,product );

We can also include few things like \n ,\t which are special . \n is used when you want a new line
\t is used for tab space and etc . The are used as placeholders for formatting .
 So printf is a type of  formatted output .

Scanf()

Syntax : scanf("Placeholder ", address list);
 Example: scanf("%d",&a);

Now breaking down the scanf statement. Its very similar to the printf but here one thing we need to note is we use the address list instead of argument list. Now what is address list ?? Its simple instead of just writing the variable name we just add a & symbol to point to its address.

the placeholder is used to denote what type of data is being read through the keyboard. The address list is used to store the data coming from the keyboard to the variable . For example
scanf("%d",&a);
The statement above the data type read is int and the data is stored in the address of variable a . So next when we use a in the program the data in the location is used.

Few Examples Of scanf Statements

scanf("%d %d ",&a,&b);
scanf("%f %f  %f",%a,&b,&c);
scanf("%d%f %c",&integer,&float,&character);


This ends the post on getting data from the user and showing him the result




Sunday, October 13, 2013

Data Types In C

Now back to some theory , from the previous programs we used something called an int where we declared variables and used a placeholder %d in the printf statements
Now let us look at in in detail . C is a strongly typed language meaning it is strict and when we declare a variable we need to tell C what kind of variable it is (what value will it hold ).
This is known as the Data  Type . Here are a few inbuilt data types in C with some information about them
       Name                Type       Storage Size         Placeholder
  1. Integer             int          2 or 4 bytes           %d
  2. Decimal           float        4 bytes                  %f
  3. Character         char         1 byte                   %c
These are the data types . They can be modified using modifiers about which we will see in later posts

we will be commonly using char , int , float. 

Please note that in this blog we are dealing with C programming from a practical point of view. We are not concerned with in depth knowledge of C but only about how to write your own 
programs using the basics..

In the previous programs we used the int datatype . Which didn't give you correct results during the division operation as it rounded off the quotient . We will look at how we can use other datatypes in the coming posts .. Stay Tuned..................




Wednesday, October 9, 2013

Bigger Of Two Numbers

Before going back to more of theory let us try out a few more simple C programs, like finding the bigger of two numbers or smaller of two numbers etc ....

Here is the program
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter two numbers");
scanf("%d%d",&a,&b);
if(a>b)
printf("%d is greater than %d",a,b);
else printf("%d is greater than %d",b,a);
getch();
}
This program finds the bigger of the two numbers that have been input by the user.



Wednesday, October 2, 2013

Variations : Subtracting ,Multiplying , Dividing

Now lets take a look at other things you can do by using the last program by just changing one line .

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sum,difference,product,quotient ;   // Variables for storing that input and output
printf("\n Enter the first number: ")
scanf("%d",&a);
printf("\n Enter the second number: ");
scanf("%d",&b);
sum=a+b; // Calculate sum
difference=a-b; // Calculate difference
product=a*b; // Calculate product
quotient=a/b; // Calculate quotient
printf("\n Sum Is %d \n Differrence is %d \n Product is %d \n Quotient is %d\n ",sum,difference,product,quotient);
getch(); // Wait till any key is pressed
}