Program 6:- Write a program to demonstrate the use of int and input function.
Answers
print ( ' Please Enter Number ' )
Num1 = input ( )
print ( ' Num1 = ' , Num1 )
print ( type (Num1) )
print ( ' Converting type of Num1 to int ' )
Num1 = int (Num1)
print (Num1)
print (type (Num1) )
*Output*
Please Enter Number 12
Num1 = 12
<class 'str'>
Converting type of Num1 to int
12
<class 'int'>
Answer:
Make mY anSWer bRaINlist
Explanation:
C Output
In C programming, printf() is one of the main output function. The function sends formatted output to the screen. For example,
Example 1: C Output
#include <stdio.h>
int main()
{
// Displays the string inside quotations
printf("C Programming");
return 0;
}
Output
C Programming
How does this program work?
All valid C programs must contain the main() function. The code execution begins from the start of the main() function.
The printf() is a library function to send formatted output to the screen. The function prints the string inside quotations.
To use printf() in our program, we need to include stdio.h header file using the #include <stdio.h> statement.
The return 0; statement inside the main() function is the "Exit status" of the program. It's optional.
Example 2: Integer Output
#include <stdio.h>
int main()
{
int testInteger = 5;
printf("Number = %d", testInteger);
return 0;
}
Output
Number = 5
We use %d format specifier to print int types. Here, the %d inside the quotations will be replaced by the value of testInteger.
Example 3: float and double Output
#include <stdio.h>
int main()
{
float number1 = 13.5;
double number2 = 12.4;
printf("number1 = %f\n", number1);
printf("number2 = %lf", number2);
return 0;
}
Output
number1 = 13.500000
number2 = 12.400000
To print float, we use %f format specifier. Similarly, we use %lf to print double values.