Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

In C, how do I print this?

I need to print the following on one line:

an integer, followed by a string, and a different string.

(and then next line)

EX: 5 is a nice number, 7 however is not.

I'm a bit confused by C's printf functions, can't figure out how to do this.

And what is actually %d/n?

Thanx in advance for any help!

3 Answers

Relevance
  • roger
    Lv 7
    10 years ago
    Favorite Answer

    %d is the printf specifier to print an int in decimal format.

    /n prints the characters / and n

    if you want a new line print \n

    look here for more help:

    http://www.codingunit.com/printf-format-specifiers...

    #include <stdio.h>

    int main(void){

    char * s1="is a nice number.";

    char * s2="however is not.";

    int a,b;

    a=5;

    b=7;

    printf("%d %s %d %s\n",a,s1,b,s2);

    ......

    Source(s): programming since 1968
  • 10 years ago

    use the format strings eg:

    int x = 5

    int y = 7

    printf("%d is a nice numer, %d however is not \n", x ,y)

    the order that the variables are placed is the order in which they will be printed out

  • 10 years ago

    %d is to indicate that the value will be in form of decimal values.

    /n for new character line

    eg .

    printf("/n hellow /n frnd");

    hellow

    frnd

    just look the link to see more parameters :

    http://www.cplusplus.com/reference/clibrary/cstdio...

Still have questions? Get your answers by asking now.