0% found this document useful (0 votes)
61 views

Components of A Computer System: - Input Devices - Output Devices - CPU - Central Processing Unit - Memory

Here are the printf statements to print the given values: 1. printf("%d", z); 2. printf("%f", balance); 3. printf("John, H.No 45, Main Street, Mumbai, 400086"); 4. printf("%c %c", str, digit); 5. printf("Current Reading = %d Previous Reading = %d Bill = %f", curr_read, pre_read, bill); 6. printf("Salary = %f Bonus = %f Grade = %c Registration No = %d", salary, bonus, grade, reg_no);
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Components of A Computer System: - Input Devices - Output Devices - CPU - Central Processing Unit - Memory

Here are the printf statements to print the given values: 1. printf("%d", z); 2. printf("%f", balance); 3. printf("John, H.No 45, Main Street, Mumbai, 400086"); 4. printf("%c %c", str, digit); 5. printf("Current Reading = %d Previous Reading = %d Bill = %f", curr_read, pre_read, bill); 6. printf("Salary = %f Bonus = %f Grade = %c Registration No = %d", salary, bonus, grade, reg_no);
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Components of a Computer System

• Input Devices
• Output Devices
• CPU – Central Processing Unit
• Memory
Input Devices
Used: The data entered into the computer
Output Devices
Used: To provide output(i.e., result) to the user.
CPU-Central Processing Unit
Used: Processes the input data
Memory
Used: To store
Data
Instructions
Results
Output -- Operation What is printf ( ) function

Rules for writing the printf( ) function

Examples programs

Input -- Operation What is scanf( ) function

Rules for writing the scanf( ) function

Examples programs
Input / Output functions in C

• Input / Output operations are performed in C using


functions.

• These functions are already defined in C and they


should be used in the way as they are given.
Output function: printf( )
• It is an output function.

Identification of function:
• Parenthesis (i.e., ( ) ) should be followed by function name.
Examples:
printf( ) --- is a function
( )printf --- not a function
printf --- not a function
print f( ) --- not a function
• It prints the result on the console-output device i.e.,
monitor.

Monitor
• The general format of printf( ) is as follows:

Syntax:

printf( “ format strings ” , variables list ) ;

Format Strings
1. Format strings are also called as format specifiers, which
controls the format of the variables to be printed.

2. Each format specifiers has to be precede with a % sign.


• The following are the various format specifiers.

Format Specifier Meaning

%d Decimal Integer

%c Character

%f Single-Precision floating point

%lf Double-Precision floating point


Variables list

• It specifies the variable names whose values should be printed.

• The above format specifiers specify in which format the value


of variable to be printed on the monitor.
Syntax: To print Message

printf ( “ Message “ ) ;
Example-1: To Print Integer Value

main()
{
int n=10;
printf(“%d”, n);
}
Example-2: To Print Character Value

main()
{
char ch=‘A’;
printf(“%c”, ch);
}
Example-3: To Print Two Integer Values and One
Character Value

main()
{
int num = 200,sum = 0;
char opt = ‘+’;
printf(“%d %d %c”, num, sum, opt);
}
Example-4: To print One Real Value, Two Character
Values, and One Integer Value

main()
{
float si = 506.75;
char ch1 = ‘B’ , ch2 = ‘z’;
int bonus = 1200;
printf(“%f %c %c %d”, si, ch1, ch2, bonus);
}
Example-5: To Print Negative Integer Value

main()
{
int a = -59;
printf(“%d ”, a);
}
Example-6

• To Print welcome to C-Language

main()
{
printf(“welcome to C-Language”);
}
Note:
Format specifiers can also contain any text has to
be printed along with the values.
Example-7: To Print Integer Value with Text Message

main()
{
int total = 505;
printf(“Total = %d”, total);
}
Example-8: To print 3 integer values, one float value, and
one character value

main()
{
int m1 = 50, m2 = 78, total = 128;
float avg = 64;
char grade = ‘A’;
printf(“marks1 = %d marks2 = %d total = %d average
= %f grade = %c”,m1, m2, total, avg, grade);
}
Note:

printf() function declaration is included in stdio.h

stdio.h --- standard input output header file


Practice…….
Write the printf( ) to print the following

1. int z = 9;
2. float balance = 4500;
3. To print your address ( name, h.no, street, city, pincode )
4. char str = ‘@’, digit = ‘6’
5. int curr_read = 350, pre_read = 300;
float bill = 150.00;
6. float salary = 10000.45, bonus =500;
char grade = ‘A’;
int reg_no =5001;

You might also like