Sunday, 17 June 2012

Sir Asdullah Bhatti The 7th lecture


LECTURE#07
CONSOLE I/O IN C LANGUAGE

SUMMARY
·         Output on console
·         Input @ console

Printf () is the builtin library function for sending something on the screen and it is provided by stdio.h header file, and on the other hand scanf( ) is another function for scanning input from the user on the console screen
<Stdio.h> stands for standard input and output, you must include this file on the top to use console i/o printf and scanf functions.

Both functions use some format specifiers for different data types like

For integers %d
For Float %f
For Char %c
For String %s
For Hexa decimal %x
For unsigned int %u
For double %ld


How to use printf() and scanf() you must take the Reference of  P#1, P#3 & P#4 of PPB


PPB

01

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




02



#include<conio.h>
#include<stdio.h>
main()
{
     
      printf("Integer occupies %d bytes",sizeof(int));
      printf("\n");
      printf("float occupies %d bytes",sizeof(float));
      printf("\n");
      printf("char occupies %d bytes",sizeof(char));
     
     
      getch();}




03




#include<conio.h>
#include<stdio.h>
main()
{
      //use of %d - Format Specifier in printf function
     
      int x,y;
     
      printf("Enter first value:");scanf("%d",&x);
      printf("Enter second value:");scanf("%d",&y);
     
      printf("\n\n");
      printf("\n %d + %d = %d",x,y,x+y);
      printf("\n %d - %d = %d",x,y,x-y);
      printf("\n %d * %d = %d",x,y,x*y);
      printf("\n %d / %d = %d",x,y,x/y);
     
     
      getch();}




04




#include<conio.h>
#include<stdio.h>
main()
{
      //implementation of arithmatic operators
      int x,y;
      printf("Enter first value:");scanf("%d",&x);
      printf("Enter second value:");scanf("%d",&y);
      printf("\n\n");
      printf("\nSum = %d",x+y);
      printf("\nDiff = %d",x-y);
      printf("\nProduct = %d",x*y);
      printf("\nDivision = %d",x/y);
      getch();}
 

No comments:

Post a Comment