PST Unit-2 After Variables gWofFW
PST Unit-2 After Variables gWofFW
Example:-
1) Declare an integer Variable int sum;
2) Declaring Floating point variable float avg;
3) Declare Character Variable char ch;
4) Declare Double Precision Variable double d;
5) Declare Multiple Integer Variable in single declaration statement
int a1,a2,a3,a4;
25. What are the Console input/output functions? Mention its types?
• Console Input/output Functions: Console Input Output functions help to
read data from Keyboard and Print/ Display data to the Monitor or screen.
• Types:-
1) Formatted Input/Output Functions.
2) Unformatted Input/Output Functions.
26. Explain Formatted Input/Output Functions?
• Formatted Input/output Functions that allow input and output operations to
be performed in a specified and desired format.
OR
• Formatted I/O functions are used to take various inputs from the user and
display multiple outputs to the user.
• These types of I/O functions can help to display the output to the user in
different formats using the format specifiers. These I/O supports all data
types like int, float, char, and many more.
• Example: The Formatted I/O Functions are scanf() and printf().
• The printf() is used to display the formatted data items on the standard
output device normally the monitor.
• The scanf() is used to read the formatted data input from the standard input
device normally the keyboard.
• These functions are defined in the header file stdio.h and return EOF if there
occurs an error or end of file.
Note:-
The ampersand symbol & before variable name is an operator that
specifies the variable name’s address.
Examples for scanf():-
1) int a; 6) int a, b, c;
3)float f; 8) int a, b, c, v;
4)double d;
scanf(“%lf”, &d);
5) int a;
float f;
double d;
scanf(“%d %f %lf ”, &a, &f, &d);
Example:-
Program to illustrate the return value of scanf():-
#include<stdio.h>
#include<conio.h>
main()
{
int a ,b, c, v;
printf(“Enter the values of a, b and c \n”);
v= scanf(“%d %d %d”, &a, &b, &c);
printf(“\n Number of values successfully read is: %d”, v);
getch();
}
Output:-
Enter values of a, b and c
10 20 30
Number of values successfully read is: 3
Example:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10;
float f=3.142;
double d= 8.525;
char ch = ‘A’
printf(“%d %f %lf %c”, a, f, d, ch);
}
Output:-
10 3.142 8.525 A
Examples:-
1)main()
{
printf(“Programming in C \n”);
printf(“For Beginners”);
}
Output:-
Programming in C
For Beginners
2)main()
{
printf(“Programming in C \t”);
printf(“For Beginners”);
}
Output:-
Programming in C For Beginners
Example:-
32. Explain Field Width Specification for printing Decimal numbers
or float with Examples?
• The syntax of specifying field width for float values is shown below.
• Syntax:-
%W.Xf right justified
%-W.Xf left justified
where
W indicates total number of columns required to print the value. It is also called
the total width of the output.
X is the number of columns used after the decimal part.
f is the format specifier for float data type.
Example:-
33. Explain Field Width Specification for printing Character and
string with Examples?
• The syntax of specifying field width for strings and single characters is
shown below.
• Syntax:-
%W.Xs right justified
%-W.Xs left justified
where
W indicates total number of columns reserved to print the string.
X is the number of columns used to print the string in right justified way. The rest
of characters are ignored.
s is the format specifier for string.
Example:-