What will be the output of the following program?
#include<stdio.h>
int max(int x, int y)
{
return (y > x)?y: x;
}
void main()
{
int a[ ] = {2,6, 0, 7, 2,0, 1,5};
int z = a[0], n=8, i=0,c=a[0];
for (i = 1; i<n; i++)
{
c = max(a[i], C+a[i]);
z = max(z, c);
}
printf("%d\n", z);
}
Answers
Explanation:
Format specifiers in C
The format specifier is used during input and output. It is a way to tell the compiler what type of data is in a variable during taking input using scanf() or printing using printf(). Some examples are %c, %d, %f, etc.
The format specifier in printf() and scanf() are mostly the same but there is some difference which we will see.
printf(char *format, arg1, arg2, …)
This function prints the character on standard output and returns the number of character printed the format is a string starting with % and ends with conversion character (like c, i, f, d, etc.).
Between both, there can be elements governing the printing format. Below is its description
A minus(-) sign tells left alignment.
A number after % specifies the minimum field width to be printed if the characters are less than the size of width the remaining space is filled with space and if it is greater than it printed as it is without truncation.
A period( . ) symbol separate field width with the precision.
Precision tells the maximum number of digits in integer, characters in string and number of digits after decimal part in floating value.
Lets see these..
Character format specifier : %c
#include <stdio.h>
int main()
{
char ch = 'A';
printf("%c\n", ch);
return 0;