OUTPUT Statements
OUTPUT Statements
This is the most commonly used function for outputting a data of any type.
It is also known as formatted output statement.
It is used to display result of variables on the screen.
It is also used to display any message on the screen.
Syntax :
Examples:
(3)printf("Hello, ");
printf("world!\n");
Output :
Hello, world!
CBPCC Page 1
Example:
#include <stdio.h>
#include <conio.h>
void main()
{
char ch = 'A';
char str[30] = "c.b.patel computer college";
float flt = 10.234;
int no = 150;
double dbl = 20.123456;
Output:
Character is A
String is c.b.patel computer college
Float value is 10.234000
Float value is 10.23
Integer value is 150
Double value is 20.123456
Octal value is 226
Hexadecimal value is 96
While inputting or outputting data field, width can also be specified. For assigning
field width, width is placed before the conversion character like “%10f”, ”%8d”,
”%12e” and so on… Also we can display data to a fixed no of decimal places.
Syntax:
putchar(char c);
Example:
char c;
c = ‘a’;
putchar(c);
2. putch() function
putch displays any alphanumeric character to the standard output device.
It also displays only one character at a time on the screen.
Syntax:
putch(char c);
Example:
char c;
c = ‘a’;
putch(c);
3. puts() function
Example:
#include<stdio.h>
#include<conio.h>
void main()
{
char a[20];
gets(a);
puts(a);
getch();
}
CBPCC Page 3
Note:
putch comes from standard library conio.h and it is not supported on Linux OS.
putchar comes from stdio.h and you can use it with no problems on Linux OS.
Programs
CBPCC Page 4