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

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

Top comments (0)

AWS Industries LIVE! Stream

Watch AWS Industries LIVE!

New tech. Real solutions. See what’s possible on Industries LIVE! with AWS and AWS Partners.

Learn More

👋 Kindness is contagious

DEV works best when you're signed in—unlocking a more customized experience with features like dark mode and personalized reading settings!

Okay