Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
Goeduhub's Online Courses @ Udemy in Just INR 570/-
Online Training - Youtube Live Class Link
0 like 0 dislike
in Tutorial & Interview questions by Goeduhub's Expert (8.3k points)

Goeduhub's Top Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-


Course Name



Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon


Natural Language Processing-NLP with Deep Learning in Python Apply Coupon


Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon
    More Courses

1 Answer

0 like 0 dislike
by Goeduhub's Expert (8.3k points)
Best answer

Reading data from input devices and displaying the results on the screen are the two main tasks of any program which performed by printf and scanf. 

Both functions are inbuilt library functions, defined in stdio.h (header file). We have to include “stdio.h” file as shown in below C program to make use of these printf() and scanf() library functions in C language.

printf() function

The printf() function is used for output. It prints the given statement to the console.

  • We use printf() function with %d format specifier to display the value of an integer variable.
  • Similarly %c is used to display character, %f for float variable, %s for string variable, %lf for double and %x for hexadecimal variable.
  • To generate a newline,we use “\n” in C printf() statement.
  • C language is case sensitive. All characters in printf() and scanf() functions must be in lower case.

#include <stdio.h>

int main()
   char ch = 'G';
   char str[20] = "";
   float flt = 40.123;
   int no = 10;
   double dbl = 10.123456;
   printf("Character is %c \n", ch);
   printf("String is %s \n" , str);
   printf("Float value is %f \n", flt);
   printf("Integer value is %d\n" , no);
   printf("Double value is %lf \n", dbl);
   printf("Octal value is %o \n", no);
   printf("Hexadecimal value is %x \n", no);
   return 0;

scanf() function 

The scanf() function is used for input. It reads the input data from the console. 

#include <stdio.h>

int main()


   char ch;

   char str[100];

   printf("Enter any character \n");

   scanf("%c", &ch);

   printf("Entered character is %c \n", ch);

   printf("Enter any string ( upto 100 character ) \n");

   scanf("%s", &str);

   printf("Entered string is %s \n", str);


3.3k questions

7.1k answers


4.5k users

Related questions

0 like 0 dislike
1 answer 109 views
0 like 0 dislike
1 answer 75 views
0 like 0 dislike
1 answer 128 views
0 like 0 dislike
1 answer 104 views
0 like 0 dislike
0 answers 82 views


About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © Social::   |  |