Basic Input and Output

 [Home Page]  [Back]  [Content of Contributions]  [Movement: Green Leaf World]

Program 01

#include<stdio.h>  //HEADER FILE INCLUSION
int main (void)
{

//VARIABLE DECLARATION AREA
  int a;
  char b;
  float c;

  system("clear");   //in windows use clrscr();
  printf("\n\n\t\t\tThis is Our First C Program\n\n");  //PRINTING MESSAGE

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

  printf("%c", b);
  printf("%d", a);
  printf("%f", c);

  return(1);
}


Output:
 
            This is Our First C Program

a
10
10.123
a1010.123000skm@skm-ThinkPad-L430:~$


Program 02

#include<stdio.h>
int main (void)
{
  int a;
  char b;
  float c;

  system("clear");
  printf("\n\n\t\t\tThis is Our Second C Program\n");

  printf("\nEnter a character: ");
  scanf("%c", &b);
  printf("\nEnter an Integer: ");
  scanf("%d", &a);
  printf("\nEnter a Real Number: ");
  scanf("%f", &c);

  printf("\n\nEntered character: ");
  printf("%c", b);
  printf("\nEntered integer: ");
  printf("%d", a);
  printf("\nEntered real no: ");
  printf("%f\n\n", c);

  return(1);
}


Output:
 
            This is Our Second C Program

Enter a character: a

Enter an Integer: 10

Enter a Real Number: 10.123


Entered character: a
Entered integer: 10
Entered real no: 10.123000

skm@skm-ThinkPad-L430:~$

Program 03

#include<stdio.h>
int main (void)
{
  int a;
  char b;
  float c;

  system("clear");
  printf("\n\n\t\t\tThis is Our Third C Program\n");

  printf("\nEnter a character: ");
  scanf("%c", &b);
  printf("Enter an Integer: ");
  scanf("%d", &a);
  printf("Enter a Real Number: ");
  scanf("%f", &c);

  printf("\n\nEntered character: %c", b);
 
  printf("\nEntered integer: %d\nEntered real no: %f\n\n", a, c);

  getchar();
  return(8);
}


Output:
 
       
            This is Our Third C Program

Enter a character: a
Enter an Integer: 10
Enter a Real Number: 10.123


Entered character: a
Entered integer: 10
Entered real no: 10.123000

skm@skm-ThinkPad-L430:~$



Remember:
  1. printf(), scanf(), system(), getchar() are library functions. We must include stdio.h header file to use any of this functions in a program code.
  2. A C program code is also called source code.
  3. Any C program code must be compiled before execute.
  4. Once a program code is compiled, you may execute it several times.
  5. It is a good practice to show messages before any input statement.
  6. You must be aware about visibility & clarity of the outputs.
  7. "%" with printf()/ scanf() is used as format specifier to define the format of the data. The formats are
    1. %d  - Integer(signed)
    2. %u  - Integer(unsigned)
    3. %ld - Integer(Long signed)
    4. %c  - Character(char)
    5. %f  - Real(float)
    6. %lf - Real(Double)
    7. %Lf - Real(Long Double) 
    8. etc.
 

No comments:

Post a Comment