Printf in c

Printf in c

Output data can be written from user input or from memory to the console and output device(monitor) using printf() library function. with printf() function all types of values such as(numerical,character or string)can be written as output the printf() function can be written as–


printf("control strings",variable1,variable2,variable3......);

in C printf() function | writing output in c, in this printf() function, the first control string contains conversion specification characters and text. The first control string should be enclosed with in double quotes. In the second part the variables not followed by an ampersand(&) sign. If the control string does not contain any conversion specification, the variables name not specified. Here is some Examples–

int main()
{
printf(″C language has powerful tools″);
}

In this example. In the printf() function the control string contains only text and no conversion specification characters, so the output will be only text that written in the printf()

int main()
{
int marks;

printf("Enter the marks");
scanf("%d",&marks);
}

Enter the marks 100

In this above example the printf() function does not contain any conversion specification character. its contains only text to print so its used to display message. And tell to user to enter marks –

float salary=300.60;
printf("%f",salary);

In the above example first parameter control string contains the conversion specification character %f, which means that floating point value will be display. The variable salary has floating value to display as output

char str='A';
printf("%c",str);

In the above example first parameter conversion specifier character %c. That means a single character will be display and variable str has that character value

#include<stdio.h>
void main()
{
char name[10]="Nitish";
printf("%s",name);
}

Output

Nitish

In the above example first parameter conversion specifier character %s indicates that string will be display and variable name is the type of character array that stored the string which will be display.

#include<stdio.h>
void main()
{

char name[10]="Nitish";
float average=90.7;
int roll;

printf("%s %f %d",name,average,roll);
}

Output

Nitish 90.699997 4195504