Output Function in C programming
C Output Function
C programming language provides built-in functions to perform output operation. The output operations are used to display data on user screen (output screen ) or printer or any file.
printf() function
The printf() function is used to print string or data values or a combination of string and data values on the output screen.
Syntax:
printf("message to be displya");
program-Write a program to print "hello world " using printf().
Code:
#include<stdio.h>
void main()
{
printf("hello world");
}
Output:
hello world
--------------------------------
we used the printf() function to print a string on to the output screen
The printf() function is also used to display data values. when we want to display data values we use format string of the data value to be displayed.
Syntax:
printf("format string ", varaibleName);
program:
#include<stdio.h>
void main()
{
int i=10;
float x=5.5;
printf("%d %f",i,x);
}
Output:
10 5.500000
--------------------------------
The printf() function can also be used to display string along with data values.
Syntax :
printf("String format", variableName);
program:
#include<stdio.h>
void main()
{
int i=10;
float x=5.5;
printf("Integer=%d, float value=%f",i,x);
}
Output:
Integer=10, float value=5.500000
--------------------------------
putchar() function
The putchar() function is used to display a single character on output screen. The putchar() function prints the character which is passed as a parameter to it and returns the same character as a return value.
This function is used to print only a single character.
Program:
#include<stdio.h>
void main()
{
char ch='A';
putchar(ch);
}
Output:
A
--------------------------------
puts() function
The puts() function is used to display a string on the output screen. The puts() function prints a string or sequence of characters till the newline.
Program:
#include<Stdio.h>
void main()
{
char name[30];
printf("Enter your favorite website:");
gets(name);
puts(name);
}
Output:
Enter your favorite website:rajanshukla1.blogspot.com
--------------------------------
Comments
Post a Comment