Showing posts with label K&R. Show all posts
Showing posts with label K&R. Show all posts
Monday, March 7, 2016
Use of getchar() ,putchar() functions
Use of getchar() ,putchar() functions
The use of getchar function is to capture or get the data / the typed character from (single chara) keyboard .
the putchar() is do just opposite of getchar()
It prints directly to the screen , so we dont need use the printf() function .
Look the program and output
here used getchar() function to get char.
putchar() and printf() function is used to print the given data.
Char Data Type
the char is used to storing simple character
Unsigned: It consist only positive value i.e 0 to 255.
-1 to -128
Signed: It consist both negative and positive values but in different formats like
- 0 to +127
And this all explanation is about 8 bit number system
Char has 1 byte only
int main()
{
char a ;
etc
Char has 1 byte only
int main()
{
char a ;
etc
Working of a floating point data type
Working of a floating point data type
Look and understand the program and output shown below simple understand what will
happen there #include
#include
int main(){
float far = 10;
printf("%1.0f\n", far );
printf("%2.0f\n", far);
printf("%3.0f\n", far);
printf("%4.0f\n", far);
printf("%5.0f\n\n", far);
printf("%1.1f\n", far );
printf("%1.2f\n", far);
printf("%1.3f\n", far);
printf("%1.4f\n", far);
printf("%1.5f\n", far);
getch();
return 0;
}
Working Of while loop
The while loop operates as follows , the condition is tested ,if the it is true .
That is the condition is true that means
for example
10 == 10 . or 10<20 .="" etc="" p="">If it is true the statement in the while loop will be work or execute
while(i < j )
{
stament for exection
}
Example
while(far <= upper )
20>
That is the condition is true that means
for example
10 == 10 . or 10<20 .="" etc="" p="">If it is true the statement in the while loop will be work or execute
while(i < j )
{
stament for exection
}
Example
while(far <= upper )
20>
{
celsius = 5 * (far - 32)/9;
printf("%d\t%d\n", far ,celsius);
far += step;
}
it will execute till until the condition will get false .
that is the far not equal to upper
NB :
The body of the while loop may be single or more line .
If there is a single line there is no need to add a the curly {} bracket
Eg :
while(i < j)
i = 2 * i ; // it will repeat until the condition fall
Introduction to c programming
Introduction to c programming
First Program
Hello World Program
We need to compiler and an IDE I am using Dev C++ IDE very good and simple one
It is a free and Open Source IDE .And small in size download it from Here Click Here
first Program
To print out the following words hello World
Wednesday, September 16, 2015
Shift Operator Tutorials in C
SHIFT OPERATION IN C
I had more times learned the bit shift operator after some days i am forgetting that . so i am expressing the details how it works . through this i can rewind this post to learn it ..
Left shift operator
The syntax for writing shift operator as follows
[variable]<<[number of places]
1<
Here 1 is variable ,the operator << ; left shift and a is the number ie, how much bit position is needed to shift to left.
In detail :
In the LEFT shift (<<) first you write an N number of of zeros , where the 'N" is the number placed in number of places
for Example :
1) 1<<3 font="">3>
ie , 1 will be left shift by putting 3 zeros
ie, 1 wrote first and put 3 zeros
1000
finally
1<<3 1000="" 16="" binary="" decimal="" font="" in="" or="">3>
Example 2)
3>>3;
11... then 3 zeros
11000 = 24 in decimal
Example 3)
5<<3 comment-3--="">3>
101... 000
ie 101000
Example 3) 3<<5 comment-5--="">5>
1100000
***********************************************************************************
Subscribe to:
Posts (Atom)
