Components of A Computer System: - Input Devices - Output Devices - CPU - Central Processing Unit - Memory
Components of A Computer System: - Input Devices - Output Devices - CPU - Central Processing Unit - Memory
• 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
Examples programs
Examples programs
Input / Output functions in C
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:
Format Strings
1. Format strings are also called as format specifiers, which
controls the format of the variables to be printed.
%d Decimal Integer
%c Character
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
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:
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;