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 given below:
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
We should see a basic case of c language that gets
contribution from the client and prints the 3D shape 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
|
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:9
enter second number:9
sum of 2 numbers:18
|
Where to Play Roulette in 2021 - DRMCD
ReplyDeleteFind the 광양 출장마사지 best online 태백 출장마사지 roulette games in US, Canada 안동 출장마사지 and Asia. The best gambling 강릉 출장안마 sites, with roulette games, jackpots, and a range of 전라북도 출장마사지