#include<stdio.h>
#include<conio.h>
int main()
{
int x;
float y;
char z;
double p;
x=20;
y=2e1; //e is called mantissa exp 2.4561 is the mantissa and +3 is the exponent//
z='a'; //single quotation mark use for one character and double quotation mark use for string//
p=3.2e20;
printf("\n %d %20.2f %c %.21f",x,y,z,p);
getch();
}
The above code is a C program that declares and assigns values to four variables: an integer variable x
, a floating-point variable y
, a character variable z
, and a double precision variable p
.
- The program starts by including the standard input/output header file
stdio.h
and the non-standard conio.h header file which provides thegetch()
function. - Inside the
main()
function, it declares four variablesx
,y
,z
andp
with the int, float, char and double data types respectively. - It assigns the value 20 to the variable
x
, the value 2e1 to the variabley
, the value ‘a’ to the variablez
and 3.2e20 to the variablep
. It’s important to note that2e1
and3.2e20
are both in scientific notation. The number before thee
is the mantissa and the number after thee
is the exponent. So 2e1 is equal to 2*10^1 = 20. - The program uses the
printf()
function to print the values of the variablesx
,y
,z
andp
. The format specifiers used are%d
for integer,%20.2f
for floating point,%c
for character and%.21f
for double. - The
%20.2f
format specifier is used to format the floating-point variabley
. The20
specifies the field width, and the.2
specifies the number of digits to be printed after the decimal point. - The
%c
format specifier is used to format the character variablez
. It prints the value of the variable as a single character. - The
%.21f
format specifier is used to format the double precision variablep
. The.21
specifies the number of digits to be printed after the decimal point. - The
getch()
function is used to wait for the user to press a key before terminating the program.
It’s important to note that the getch()
function is not a part of the standard C library, it is provided by the non-standard conio.h header file and it’s use is not recommended in most cases.
Thanks
Write a program on various constants.