Wednesday, 4 March 2015

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:




No comments:

Post a Comment