Skip to main content

Input-Output in C programming

Input-Output in C

In this post, we will learn how to take an input from terminal and display/print on the terminal. We take a input from the terminal to fill dynamic value in a variable.

Introduction

In c programming, we scanf() function to take an input from terminal and printf() function to displace value of a variable on the terminal.

Integer Input-Output in C program

In C programming we use scanf() function with parameters %d and &variable_name to take an integer input from the terminal and printf() function to print the variable value on the terminal.
 #include <stdio.h>  
 int main()  
 {  
      int variable;  
      scanf("%d", &variable);  
      printf("%d", variable);  
      return 0;  
 }  
In above example,
int variable; means decler a variable with name variable you can keep any name
scanf("%d", &variable); means take a input from termial-keyboard and strore in variable variable 
printf("%d", variable); means print value of variable variable on terminal
Float Input-Output in C program
We use %f at the place for %d in order to store float variable in c programming language
 #include <stdio.h>  
 int main()  
 {  
      float variable;  
      scanf("%f", &variable);  
      printf("%f", variable);  
      return 0; 
 }  
In above example,
float variable; means decler a variable with name variable you can keep any name
scanf("%f", &variable); means take a input from termial-keyboard and strore in variable variable 
printf("%f", variable); means print value of variable variable on terminal

Character Input-Output in C program 

We use %c at the place for %d in order to store float variable in c programming language
 #include <stdio.h>  
 int main()  
 {  
      char variable;  
      scanf("%c", &variable);  
      printf("%c", variable);  
      return 0;  
 }  
In above example,
char variable; means decler a variable with name variable you can keep any name
scanf("%c", &variable); means take a input from termial-keyboard and strore in variable variable 
printf("%c", variable); means print value of variable variable on terminal

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Comments

Popular posts from this blog

OFFSET in Computer Science

OFFSET in Computer Science In the post, We will understand what is the meaning of OFFSET in computer science with an example. In computer science offset comes picture at may place like packing a data structure, encoding the data etc in some standard protocol so that other parties can deserialise it and understand the data. We will understand its important how does it work with example. suppose we have a data structure for a student like { name:string[20] roll: int[4] course: string[25] batch: int[4] } We want to serialise below student data  { name:"Amit Gupta" roll: 1234 course:Computer Science" batch: 2018 } Our protocol follow the rule that we will insert a value and if space will remain empty we will fill it with $ for example length of "Amit Gupta" is 10 but standard size is 20 so will fill 10 $ after "Amit Gupta". So serialisation of above data will be Amit Gupta$$$$$$$$$$1234Computer Sc...

Supplementary angles

Supplementary angles Supplementary angles  are two angles with a sum of  180 ^\circ 1 8 0 ∘ 180, degree . A common case is when they lie on the same side of a straight line.

Clique in Graph

Clique in Graph In this tutorial, we will learn about the clique in the graph theory. Clique In graph theory, a clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Madhya Pradesh Power Generation Company Limited (MPPGCL) Recruitment

 Madhya Pradesh Power Generation Company Limited (MPPGCL) Recruitment     Madhya Pradesh Power Generation Company Limited (MPPGCL)  has released a notification for the post of   Apprentice. Company Name MPPGCL Post Name    Apprentice State Madhya Pradesh Salary Rs. NM Number of Vacancy 209 Eligibility ITI Last Date 31-12-2018 Application Details Job Notification Apply Online Job Application Madhya Pradesh Power Generation Company Limited (MPPGCL) Recruitment         Government Jobs in  Madhya Pradesh Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.