Input and Output in C

input-and-output-in-c

In C programming printf() is used for outputting a data or to display a data. On the other hand, scanf() is used to take input values from the users.

Input and Output of integer value.

#include    

int main() {

  int age;

  printf("Enter Input value: ");
  scanf("%d", &age);

  printf("Age = %d", age);

  return 0;
}

Why we use & with scanf()

It is because, & helps to point towards the memory location of that variable.

Input and Output of double and char values

int main() {

  char alphabet;
  double number;


  printf("Enter a character: ");
  scanf("%c", &alphabet);

  printf("Enter a number: ");
  scanf("n%lf", &number);

  printf("alphabet is %c", alphabet);
  printf("nnumber is %.2lf", number);

  return 0;
}

Inputting 2 values together

#include 

int main() {

  char alphabet;
  double number;


  printf("Enter input values: ");
  scanf("%lf %c", &number, &alphabet);

  printf("alphabet is %c", alphabet);
  printf("nnumber is %.2lf", number);

  return 0;
}
Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
business-intelligence-and-analytics:-a-comprehensive-guide

Business Intelligence and Analytics: A Comprehensive Guide

Next Post
how-ai-can-improve-your-customer-experience-[new-data-+-tips]

How AI Can Improve Your Customer Experience [New Data + Tips]

Related Posts