TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Sunday 3 May 2020

Printf() And Scanf() In C Programming Language | Printf() And Scanf() In C Programming Language In Hindi

Printf() and Scanf() in C


The printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h (header file).


printf() function

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

The syntax of printf() function is:

printf("format string",argument_list);  

The format string can be %d (integer), %c (character), %s (string), %f (float) etc.

scanf() function

The scanf() function is used for input. It reads the input data from the console.
       
       scanf("format string",argument_list);  

Program to print cube of given number

Let's see a simple example of c language that gets input from the user and prints the cube of the given number.

      #include<stdio.h>
      int main()
     {    
      int number;    
     printf("enter a number:");    
     scanf("%d",&number);    
      printf("cube of number is:%d ",number*number*number);    
     return 0;   
     }    


Output

enter a number:5

cube of  number is:125

download image printf and scanf

Fig: Printf() and Scanf() 


The scanf("%d",&number) statement reads integer number from the console and stores the given value in number variable.

The printf("cube of number is:%d ",number*number*number) statement prints the cube of number on the console.

Program to print sum of 2 numbers

Let's see a simple example of input and output in C language that prints addition of 2 numbers.

     #include<stdio.h>    
     int main(){    
    int x=0,y=0,result=0;  
  
    printf("enter first number:");  
    scanf("%d",&x);  
   printf("enter second number:");  
    scanf("%d",&y);  
     
    result=x+y;  
     printf("sum of 2 numbers:%d ",result);  
  
    return 0;  
    }    


Output

enter first number:6

enter second number:6

sum of 2 numbers:12 

No comments:

Post a Comment