English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

main()
{
int i=3;
float j=3.5;
printf("%f",i);
printf("%d",j);
}

2007-10-23 21:38:42 · 3 answers · asked by unknown123 2 in Computers & Internet Programming & Design

3 answers

Using %f notation we print a float. Here i is a integer but printing using %f notation the it will print 3.00000

But %d notation is for integer printing so if we print a float of value 3.5 then it will print 3 only

%f -- float printing
%d -- decimal printing

2007-10-23 21:58:51 · answer #1 · answered by Cypher Team 1 · 1 0

A simple program which prints two numbers - an integer (3) and a float (3.5)

1. The first line defines the program
2. The 3-rd and 4-th lines define the type of the numbers (3 is integer, 3.5 is float) and assigns them to variables - i and j
3. The "printf" command is used to print the numbers on the screen. "%f" means that Decimal floating point will be used to format the number, "%d" means Signed decimal integer.

So the output of the program will be the numbers 3 and 3.5

I see a mistake here. Wrong formatting is used for the numbers. Choose one of the following:
1.) printf("%d",i);
printf(%f",j);

-OR-

2.) float i=3.5;
int j=3;

2007-10-24 05:18:26 · answer #2 · answered by TBird 4 · 0 0

Others have spotted the mistakes; there, but if this is just an exam question and they are making 'mistakes' purposely the traced output should be 0234327823784 or some weirdly long garbage number.

2007-10-24 05:24:33 · answer #3 · answered by Andy T 7 · 0 1

fedest.com, questions and answers