Input Output Function with answers
Input Output Function with answers
JV
C has specialised functions to handle the values that are given as input and also the
scanf()
output of the computed results. The pair of I/O functions, _________________ and
LS-3
printf()
_________________ are used in C language to read and write data in a specific format. The
print messages
The output function printf( ) is used to ____________________________ and values on
the variable. Hence, should precede each variable name while accepting values to it.
The I/O statements handle the different types of variables using the format specifier string.
specifier is ___________
%f and character variable format specifier is ___________
%c
JV
EXAMPLE PROGRAM TO EXPLAIN Printf() AND Scanf() STATEMENTS
main()
Input n1, n2
{
getch(); End
#include <conio.h>
main( ) { Result
Enter principal, interest rate and time
float p,r,t,si;
10000
clrscr();
2
printf (“Enter principal, interest rate and time\n”) 2
si=(p * r * t ) / 100;
getch();
Teacher’s Signature:
I. Fill in the blanks with the correct option HGC
9
JV
\t
1. The ______________________ character gives tab spacing.
a. \c b. \t c. & d. \n
\n
2. ______________________ character takes the cursor to new line.
a. \n b. /n c. & d. !n
W-3
&
3. The ___________ in a scanf( ) statement indicates the memory address of the variable.
a. && b. & c. \t d. %d
Variables
4. ______________________ must be declared at the beginning of the program.
a. String b. Values c. Variables d. getch( )
%c
5. ______________________ format string is used for printing character values.
a. %c b. %d c. %f d. %e
II. Shade the word that is not associated with the other three
1. %d %f %c %t
5. \n \t & &&&
JV
#include <stdio.h>
main()
{
int poc_money=30; W-3
int weekly,monthly;
weekly=poc_money*7;
monthly = poc_money * 30;
printf(“\n Pocket money spent per day - %d “,poc_money);
printf(“\n Pocket money spent per week - %d “, weekly );
printf(“\n Pocket money spent per month - %d “, monthly );
getch( ); }
#include <stdio.h>
main()
{
float p, n , r, si;
printf(“\n Enter the Principle Amount”);
scanf( “%f” ,&p);
printf(“ \n Enter the no: of years ”);
scanf(“%f”, &n);
printf(“\n Enter the Rate of Interest ”);
scanf( “%f”, &r );
si= (p * n * r) /100;
printf(“Simple Interest is %f”,si);
getch( ); }
V. Find the errors and rewrite the code in the space provided
#include<Stdio.h> #include<stdio.h>
main( ) main( )
{ {
float f,c; float f,c;
clrscr( ); clrscr( );
printf (“Enter the Fahrenheit value \n”) printf (“Enter the Fahrenheit value \n”);
printf (“%f”,&fa); scanf (“%f”,&f);
c=( f − 32 ) * 5 / 9; c=( f − 32 ) * 5 / 9;
printf (“The Centigrade value is %d ”, c); printf (“The Centigrade value is %f ”, c);
}
getch( );
}
getch( );
Teacher’s Signature: