DEV Community

Sujith V S
Sujith V S

Posted on • Edited on

1 1 1 1 1

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 <stdio.h>   

int main() {

  int age;

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

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

  return 0;
}
Enter fullscreen mode Exit fullscreen mode

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;
}
Enter fullscreen mode Exit fullscreen mode

Inputting 2 values together

#include <stdio.h>

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;
}
Enter fullscreen mode Exit fullscreen mode

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more