100% found this document useful (1 vote)
399 views2 pages

C Programming Format Practice

The document contains instructions to write and examine the output of two C programs, format.c and fmtf.c, that demonstrate different formatting specifiers in printf statements. It also contains a third program with syntax errors to identify. format.c demonstrates formatting with integer specifiers like d, formatting with sign indicators, and zero padding. fmtf.c demonstrates formatting floating point numbers with e, f, g specifiers as well as precision, width, and alternative form. The third program contains syntax errors in the function declaration, variable declarations, and printf/scanf statements that need to be corrected.

Uploaded by

msugnan9124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
399 views2 pages

C Programming Format Practice

The document contains instructions to write and examine the output of two C programs, format.c and fmtf.c, that demonstrate different formatting specifiers in printf statements. It also contains a third program with syntax errors to identify. format.c demonstrates formatting with integer specifiers like d, formatting with sign indicators, and zero padding. fmtf.c demonstrates formatting floating point numbers with e, f, g specifiers as well as precision, width, and alternative form. The third program contains syntax errors in the function declaration, variable declarations, and printf/scanf statements that need to be corrected.

Uploaded by

msugnan9124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PPS Assignment -2

1. Type the program in a file format.c and examine/understand the output.

#include<stdio.h>
int main(void)
{ int a=123,b=-123,c=12345;
printf(" 2d\n",c);
printf(" 10.2d\n",c);
printf(" -10.2d\n",c);
printf(" -7d\n",a);
printf(" 07.2d\n",a);
printf(" 07d\n",a);
printf(" +0-9.4d\n",a);
printf(" +09.4d\n",a);
printf(" +07d\n",a);
printf(" +07.4d\n",a);
printf(" +-07.4d\n",a);
printf(" -08d\n",b);
printf(" -08.2d\n",b);
printf(" -.4d\n",b);
return 0;
}

2. Type the program in a file fmtf.c and examine/understand the output.

#include
<stdio.h> int
main(void)
{ double a=12345.6789;
printf("\nFormatting with e or
E\n");
printf(" e\n",a);
printf(" 5e\n",a);
printf(" 5.2E\n",a);
printf(" 5.0E\n",a);
printf(" #5.0E\n",a);
printf(" 05e\n",a);
printf(" 010.2e\n",a);
printf(" +010.1e\n",a);
printf("\nFormatting withlf\n");
printf(" lf\n",a);
printf(" 5lf\n",a);
printf(" 4.2lf\n",a);
printf(" 10.2lf\n",a);
printf(" -10.2lf\n",a);
printf(" 10.0lf\n",a);
printf(" #10.0lf\n",a);
printf(" +010.2lf\n",-a);
printf("\nFormatting with g \n");
printf(" g\n",a);
printf(" 9g\n",a);
printf(" 4.3g\n",a);
printf(" 4.5g\n",a);
printf(" #4.5g\n",a);
printf(" #9.5g\n",a);
printf("
5.4g\n",a);
return(0);
}

3. Find the errors (if any) in the following program

#include <stdio.h>
int
main
(
)
{
int a,b
,c;
a=
2.45
;
b
=a+2;
printf(
"Enter an integer:");
scanf(
" d",
&c);
printf(
" d d d\n",a,
b,c);
retur
n 0;
}

You might also like