Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
#include <stdio.h>

void main()
{
        int a = 100;
        int b = 3;
        int c;

        c = a + b;
        printf( "a + b = %dn", c );

        c = a - b;
        printf( "a - b = %dn", c );

        /* multiplication performed before call to printf() */
        printf( "a * b = %dn", a * b );

        c = a / b;
        printf( "a / b = %dn", c );

        c = 100 % 3;
        printf( "a % b = %dn", c );
}
Posted
Updated 30-Sep-15 0:58am
v2

%d means that the output is a digit (Signed decimal integer): http://www.cplusplus.com/reference/cstdio/printf/[^]
You are missing backslash in "\n", try this:

C
#include <stdio.h>

void main()
{
        int a = 100;
        int b = 3;
        int c;

        c = a + b;
        printf( "a + b = %d\n", c );

        c = a - b;
        printf( "a - b = %d\n", c );

        /* multiplication performed before call to printf() */
        printf( "a * b = %d\n", a * b );

        c = a / b;
        printf( "a / b = %d\n", c );

        c = 100 % 3;
        printf( "a % b = %d\n", c );
}
 
Share this answer
 
v3
Comments
CHill60 30-Sep-15 7:10am    
Good spot!
Leo Chapiro 30-Sep-15 7:12am    
Thank you, mate! :)
Member 10611055 30-Sep-15 7:24am    
I also know about \n is for new line, but I attend one written exam of one company their all programs printf statement written like.. printf("%d %dn",x,y).
this type of statement also wriiten on one site i,e: http://www.exforsys.com/tutorials/c-language/c-operators.html



Leo Chapiro 30-Sep-15 7:41am    
Yes, I've taken a look, this is an error on the site!
Umm, %d is used to format the string. But here n is used along with the %d, which means there's something missing i.e. \ or n itself if you want to print n after the variable value.

So in short, it signifies a decimal number followed by a character n.

-KR
 
Share this answer
 
Run it and see.

But I suspect that the "n" part should be "\n" for a new line instead.

Why ask us to run a program for you? This is trivial: paste it into your IDE, build the app, and run it!
 
Share this answer
 
Comments
Leo Chapiro 30-Sep-15 7:42am    
>This is trivial: paste it into your IDE, build the app, and run it!

This is even more trivial: paste it into http://codepad.org :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900