Saturday 21 November 2015

Program to take input from user and print it on the screen.

//Program to take different types of input from user and print it on the screen
#include<stdio.h>
#include<conio.h>

void main()
{
      int a; // declares an integer variable and allocates memory to it
      float b; // declares a character variable and allocates memory to it
      char c; // declares an decimal variable and allocates memory to it

// Memory allocated is depended on the type of compiler

      clrscr(); // clearing the console screen (part of 'conio.h' header file)

      printf("Enter integer value: "); //asks for a integer value
      scanf("%d",&a); // stores the integer value in variable 'a'
      printf("\nEnter decimal value: "); //asks for a decimal value (upto 6 decimal places only)
      scanf("%f",&b); // stores the decimal value in variable 'b'
      printf("\nEnter character value: "); //asks for a character value (only a single character)
      scanf("%c",&c); // stores the character value in variable 'c'

//printing the value stored in the respective variables

      printf("\nInputted integer is: ",a); // "\n" is used for printing from a new line
      printf("\nInputted decimal is: ",b);
      printf("\nInputted character is: ",c);

      getch(); // holding the output screen
}

No comments:

Post a Comment