Complete the Lesson Summary HGC
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
library function ________________
stdio.h with a preprocessor directive #include must be specified
in the beginning of the program to handle the pair of I/O functions.
print messages
The output function printf( ) is used to ____________________________ and values on
the screen. The general format of printf( ) statement is
printf(“<format string>”, <list of variables>);
e.g., printf(“Answer is %d”, x);
get input from the user
The input function scanf( ) is used to ________________________________________.
The general format of scanf( ) statement is
scanf(“<format string>”, & <list of variables>);
e.g., scanf(“%d %d”, &n1,&n2);
The symbol ampersand (&) indicates the ___________________________
address (location) of
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.
For example, integer variable format specifier is ___________,
%d floating point variable format
specifier is ___________
%f and character variable format specifier is ___________
%c
The new line character _______________
\n can be used in I/O statements to take the
cursor position to a new line and ___________
\t is used to give tab settings.
Page 1
Complete the Lesson Summary (Contd …) HGC
9
JV
EXAMPLE PROGRAM TO EXPLAIN Printf() AND Scanf() STATEMENTS
/* program to add two numbers */
Start LS-3
#include <stdio.h>
main()
Input n1, n2
{
int n1, n2, sum;
sum=n1+n2
printf(“Enter two numbers:”);
scanf(“%d %d”,&n1, &n2);
sum=n1+n2; Print sum
printf(“The addition of two numbers is: %d”,sum);
getch(); End
/* Program to do simple interest calculation */
#include <stdio.h>
#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
scanf(“%f %f %f”, &p, &r, &t); Simple interest = 400
si=(p * r * t ) / 100;
printf(“Simple interest = %f \n”, si);
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
2. void printf() scanf() main()
3. a=5 a=0.7 a a=5.7e-2
4. int sum Integer sum float sum char grade
5. \n \t & &&&
6. stdio.h string.h main.h conio.h
III. Complete the flowchart for the given program
#include <stdio.h> Start
main( )
{ Input the
float pi=3.14, area; value of r
int r;
printf (“Enter the radius of the circle \n”); area = pi * r * r
scanf (“%d”,&r);
area=pi * r * r; Output the
area of the
printf (“The area of the circle is:%f”,area);
getch( );
circle
} Stop
Page 1
IV. Complete the given program in the space provided HGC
9
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: