0% found this document useful (0 votes)
92 views3 pages

Assign 1

The document contains examples of using different format specifiers in C printf statements. It shows correct and incorrect usages, and the resulting outputs. Examples include formatting integers, strings, characters, floats, scientific notation, padding and precision. The last sections provide full programs demonstrating input/output of two numbers and Fahrenheit to Celsius conversion using printf and scanf.

Uploaded by

Minhaz
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
0% found this document useful (0 votes)
92 views3 pages

Assign 1

The document contains examples of using different format specifiers in C printf statements. It shows correct and incorrect usages, and the resulting outputs. Examples include formatting integers, strings, characters, floats, scientific notation, padding and precision. The last sections provide full programs demonstrating input/output of two numbers and Fahrenheit to Celsius conversion using printf and scanf.

Uploaded by

Minhaz
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
You are on page 1/ 3

9.

5
(a) printf("%-10d\n", 10000);
The statement is correct.
1000

(b) printf( "%c\n", "This is a string" );


Correct statement : printf( "%s\n", "This is a string" );
This is a string

(c) printf( "%*.*lf\n", 8, 3, 1024.987654 );


The statement is correct.
1024.988

(d)printf( "%#o\n%#X\n%#e\n", 17, 17, 1008.83689 );


The statement is correct.
021
0X11
1.008837e+003

(e)printf( "%ld\n%+ld\n", 1000000, 1000000 );


The statement is correct.
1000000
+1000000

(f)printf( "%10.2E\n", 444.93738 );


The statement is correct.
4.45E+002

(g)printf( "%10.2g\n", 444.93738 );


The statement is correct.
4.4e+002

(h)printf( "%d\n", 10.987 );


Correct :printf( "%.2f\n", 10.987 );
9.6
a) printf( "%s\n", 'Happy Birthday' );
Correct :printf( "%s\n", "Happy Birthday" );
Happy Birthday

b)printf( "%c\n", 'Hello' );


Correct :printf( "%s\n", "Hello" );
Hello

c) printf( "%c\n", "This is a string" );


Correct :printf( "%s\n", "This is a string" );
This is a string

d) printf( ""%s"", "Bon Voyage" );


Correct segment :printf( "%s\n", "Bon Voyage" );
Bon Voyage

e) char day[] = "Sunday";


printf( "%s\n", day[ 3 ] );
Correct segment :char day[] = "SUNDAY";
printf( "%c\n", day[3] );

f) printf( 'Enter your name: ' );


Correct segment :printf( "Enter your name: \n");
Enter your name

g) printf( %f, 123.456 );


Correct segment :printf( "%f\n", 123.456 );
123.456

h) printf( "%s%s\n", 'O', 'K' );


Correct :printf( "%c%c", 'O', 'K' );

i)char s[ 10 ];
scanf( "%c", s[ 7 ] );
Correct :char s[10];
printf( "%c\n", s[7] );
(9.7):
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int x,y;
printf("Enter two same type number: ");
scanf("%i%d",&x,&y);
printf("%d %d\n",x,y);
return 0;
}
Enter two same type number: 10:10
10 10
Enter two same type number: -10:-10
-10 -10
Enter two same type number: 010:010
8 10
Enter two same type number : 0x10: 0x10
16 0

(9.13):
#include <stdio.h>
#include <stdlib.h>
int main()
{
int fahrenheit;
float celsius;
printf("Enter a temperature value in Fahrenheit scale within 0 to 212: ");
scanf("%d",&fahrenheit);
celsius = (5.0/9.0)*(fahrenheit-32);
printf("\nValue of temperature in Celsius scale is %f\n",celsius);
return 0;
}

Enter a temperature value in Fahrenheit scale within 0 to 212: 198.88


Value of temperature in Celsius scale is 92.222221

You might also like