FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
554 views
in Tutorial & Interview questions by Goeduhub's Expert (9.3k points)

1 Answer

0 like 0 dislike
by Goeduhub's Expert (9.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] = "goeduhub.com";
   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);

}

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

0 like 0 dislike
1 answer 491 views
0 like 0 dislike
1 answer 658 views
0 like 0 dislike
1 answer 569 views
0 like 0 dislike
1 answer 437 views
0 like 0 dislike
0 answers 259 views

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

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

 

Free Online Directory

...