Wednesday 4 March 2015

Adding Two Numbers in C



Hay!
In this post we will teach you how to add two numbers in C language. So for this purpose we will need three integer variables or in case you want to add floating point numbers then you will need three floating point variables. We will take input of two numbers and will store it in third variable.
So lets start.


Code:



#include<stdio.h>
#include<conio.h>
void main(void)
{
int a,b,c;
printf("Enter 1st number");
scanf("%d",&a);
printf("Enter 2nd number");
scanf("%d",&b);
c=a+b;
printf("Sum is %d",c);
getch();


Output:




In Similar way you can subtract, multiply and divide two numbers just by following changes:

c=a-b for subtracting
c=a*b for multiplying 
c=a/b for dividing

Don't Forget to share your views with us. 
Read more ...

C Program to Print Integer



Hay!
In this post we will teach you that how to print integer in C language. And again we will make use of printf statement to print integer but in this post i will also teach you how to get input from user using scanf statement and its definition is also in stdio.h library file. So the the main objective is to declare an integer variable so that we can store integer number in it and print the number entered.
So lets start.


Code:





#include<stdio.h>
#include<conio.h>
void main(void)
{
int a; 
printf("Enter a Number to Print");
scanf("%d",&a);
printf("The Number You Have entered Is %d",a);
getch();

}

Now you can see that how we have used the scanf function. In scanf function the %d in inverted commas is showing is that it is a integer because for taking input and printing an integer we use %d. And &a is showing the location of veritable a which is declared above.

Similarly for other data types is given below:

%d : For taking input or printing integer 
%f : For taking input or printing floating points.
%c : For taking input or printing characters.
%s : For taking input or printing strings
ETC....


Output:




Read more ...

Tuesday 3 March 2015

Printing Hello World In C Using Printf Statement




Hay!
In this post we will teach you the first program that every new learner of C language should execute.
We will print "Hello World". For this we will use printf statement which is a library function whose definition is in the stdio.h library file. So lets start.

Syntax:

printf("Any Word,letter or phrase");

now lets try a program:

Program:





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

in this program i have used one new library function which is getch(); whose definition is in conio.h
which stands for console input output function. It is used to show output of program in console.

Output:





Other Useful information:

printf("hello world how are you");
it will print the whole sentence in one line. if you want to write "how are you" in next line or want to give space equal to 1 tab then you have to use the following escape sequences:

\n (newline)
\t (tab)
\v (vertical tab)
\f (new page)
\b (backspace)
\r (carriage return)

let me try one of them in program:




#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr() 
printf("Hello World \n How Are You");
getch();
}

Note: I have used clrscr(); statement to clear the old output.

Output:




If you Liked our post then don't forget to share your views with us. It will help us to judge our work.

Read more ...

C Data Types


C Language Data Types:

The arithmetic data types in C are Integers and floating points.


Integer Data Type:- 

Here is the detail about the standard int types and their storage size and its range also.

int: it consumes 2 bytes in memory and its range is from -32,767 to +32,767.

long int: it consumes 4 bytes in memory its range is from -2,147,483,648 to +2,147,483,648.

Unsigned int: it consumes 2 bytes in memory its range is from 0 to 65,535.

Floating Points:

Here is the detail about the standard floating point types and their storage size and its range also.

float: it consumes 4 bytes in memory and its range is from 1.2E-38 to 1.2E38.
double float: it consumes 8 bytes in memory and its range is from 2.3E-308 to 2.3E308.
long double float: it consumes 4 bytes in memory and its range is from 3.4E-4932 to 3.4E4932.


Character Data Type:
Character(char) data type include characters e.g A,a,B,C,d etc. Each character consumes only 1 byte in memory.

String:
String includes the group of characters e.g a sentence or a phrase etc. Each character in sentence of phrase consumes 1 byte.

Read more ...

Introduction to C Program Basic Structure






Hay everyone!
                     This is our first post in which we will explain you the basic structure of C Language.

Introduction to C Program Basic Structure 

Every C Program has main function which is the starting point of a program. Group of the code which explains main function is enclosed in curly(flower) braces. e.g:

void main(void) 
{
Block of Statements
}

The first void means that it will not return any value and the second void in brackets means that it don't have any argument.

User defined function can also be made in C but that we will teach you in future.


Read more ...