What does “%d! = %ld'n” mean in this code?












0














I'm still a beginner at C, so I'm finding difficulty in understanding "%d! = %ld".
I know that %d and %ld are respectively used for an integer and long, so "! =" is confusing me.



#include<stdio.h>
long factorial(int);
int main() {
int n;
long f;
printf("Enter an non-negative integer: ");
scanf("%d", &n);
if (n < 0)
printf("Negative integers are not allowed.n");
else {
f = factorial(n);
printf("%d! = %ldn", n, f); //what does this mean?
}
return 0; }
long factorial(int n) {
if (n == 0)
return 1;
else
return(n * factorial(n-1)); }









share|improve this question






















  • That's just the mathematical notation for the factorial function. It doesn't affect the %d format specifier in any way.
    – Govind Parmar
    Nov 22 at 18:01








  • 3




    have you looked at the output for clues? like the fact that the = is actually printed in the statement?
    – Claies
    Nov 22 at 18:02








  • 1




    "! =" of printf("%d! = %ldn" will print 3 characters: '!', ' ', '='.
    – chux
    Nov 22 at 18:05


















0














I'm still a beginner at C, so I'm finding difficulty in understanding "%d! = %ld".
I know that %d and %ld are respectively used for an integer and long, so "! =" is confusing me.



#include<stdio.h>
long factorial(int);
int main() {
int n;
long f;
printf("Enter an non-negative integer: ");
scanf("%d", &n);
if (n < 0)
printf("Negative integers are not allowed.n");
else {
f = factorial(n);
printf("%d! = %ldn", n, f); //what does this mean?
}
return 0; }
long factorial(int n) {
if (n == 0)
return 1;
else
return(n * factorial(n-1)); }









share|improve this question






















  • That's just the mathematical notation for the factorial function. It doesn't affect the %d format specifier in any way.
    – Govind Parmar
    Nov 22 at 18:01








  • 3




    have you looked at the output for clues? like the fact that the = is actually printed in the statement?
    – Claies
    Nov 22 at 18:02








  • 1




    "! =" of printf("%d! = %ldn" will print 3 characters: '!', ' ', '='.
    – chux
    Nov 22 at 18:05
















0












0








0







I'm still a beginner at C, so I'm finding difficulty in understanding "%d! = %ld".
I know that %d and %ld are respectively used for an integer and long, so "! =" is confusing me.



#include<stdio.h>
long factorial(int);
int main() {
int n;
long f;
printf("Enter an non-negative integer: ");
scanf("%d", &n);
if (n < 0)
printf("Negative integers are not allowed.n");
else {
f = factorial(n);
printf("%d! = %ldn", n, f); //what does this mean?
}
return 0; }
long factorial(int n) {
if (n == 0)
return 1;
else
return(n * factorial(n-1)); }









share|improve this question













I'm still a beginner at C, so I'm finding difficulty in understanding "%d! = %ld".
I know that %d and %ld are respectively used for an integer and long, so "! =" is confusing me.



#include<stdio.h>
long factorial(int);
int main() {
int n;
long f;
printf("Enter an non-negative integer: ");
scanf("%d", &n);
if (n < 0)
printf("Negative integers are not allowed.n");
else {
f = factorial(n);
printf("%d! = %ldn", n, f); //what does this mean?
}
return 0; }
long factorial(int n) {
if (n == 0)
return 1;
else
return(n * factorial(n-1)); }






c






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 17:59









Charles Abou Haidar

111




111












  • That's just the mathematical notation for the factorial function. It doesn't affect the %d format specifier in any way.
    – Govind Parmar
    Nov 22 at 18:01








  • 3




    have you looked at the output for clues? like the fact that the = is actually printed in the statement?
    – Claies
    Nov 22 at 18:02








  • 1




    "! =" of printf("%d! = %ldn" will print 3 characters: '!', ' ', '='.
    – chux
    Nov 22 at 18:05




















  • That's just the mathematical notation for the factorial function. It doesn't affect the %d format specifier in any way.
    – Govind Parmar
    Nov 22 at 18:01








  • 3




    have you looked at the output for clues? like the fact that the = is actually printed in the statement?
    – Claies
    Nov 22 at 18:02








  • 1




    "! =" of printf("%d! = %ldn" will print 3 characters: '!', ' ', '='.
    – chux
    Nov 22 at 18:05


















That's just the mathematical notation for the factorial function. It doesn't affect the %d format specifier in any way.
– Govind Parmar
Nov 22 at 18:01






That's just the mathematical notation for the factorial function. It doesn't affect the %d format specifier in any way.
– Govind Parmar
Nov 22 at 18:01






3




3




have you looked at the output for clues? like the fact that the = is actually printed in the statement?
– Claies
Nov 22 at 18:02






have you looked at the output for clues? like the fact that the = is actually printed in the statement?
– Claies
Nov 22 at 18:02






1




1




"! =" of printf("%d! = %ldn" will print 3 characters: '!', ' ', '='.
– chux
Nov 22 at 18:05






"! =" of printf("%d! = %ldn" will print 3 characters: '!', ' ', '='.
– chux
Nov 22 at 18:05














4 Answers
4






active

oldest

votes


















3














This will print:





  • %d, i.e. the decimal value of int n


  • ! =, i.e. the literal character sequence


  • %ld, i.e. the decimal value of long f






share|improve this answer





























    2














    %d and %ld are the formatting placeholders for int and long int in printf. The exclamation point is just the factorial symbol, as mentioned in the comment.






    share|improve this answer





























      1














      printf() allows you to print a string with variables inside of it. Let's say you have a variable i, containing an integer, 7.



      printf("My variable is %d", i);


      Will print



      My variable is 7


      to the console! That's because %d is how you tell printf(), "Hey, put an integer variable here!". The integer is then supplied as the next argument to the function. In your case, %d represents the integer n, and %ld represents the long integer f. Since f might be really big, we make it a long, which means more bytes are allocated to it internally on your computer. So for example, if we wanted to get the factorial of 5 and print it, we might do the following:



      printf("Factorial of %d equals %ldn", 5, factorial(5))
      // this will print "Factorial of 5 is 120" then a newline


      Oh, and n just means print a newline afterwords!






      share|improve this answer





























        0














        printf("%d! = %ldn", n, f); //what does this mean?


        %d - print an integer as a signed decimal number.



        l - specifies that the argument is a long int or unsigned long int as appropriate. %ld then prints a long int or unsigned long int



        The printed text will become something like



        n! = f 


        (factorial notation n!)






        share|improve this answer





















          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436191%2fwhat-does-d-ldn-mean-in-this-code%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          This will print:





          • %d, i.e. the decimal value of int n


          • ! =, i.e. the literal character sequence


          • %ld, i.e. the decimal value of long f






          share|improve this answer


























            3














            This will print:





            • %d, i.e. the decimal value of int n


            • ! =, i.e. the literal character sequence


            • %ld, i.e. the decimal value of long f






            share|improve this answer
























              3












              3








              3






              This will print:





              • %d, i.e. the decimal value of int n


              • ! =, i.e. the literal character sequence


              • %ld, i.e. the decimal value of long f






              share|improve this answer












              This will print:





              • %d, i.e. the decimal value of int n


              • ! =, i.e. the literal character sequence


              • %ld, i.e. the decimal value of long f







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 22 at 18:02









              DevSolar

              47.6k1294167




              47.6k1294167

























                  2














                  %d and %ld are the formatting placeholders for int and long int in printf. The exclamation point is just the factorial symbol, as mentioned in the comment.






                  share|improve this answer


























                    2














                    %d and %ld are the formatting placeholders for int and long int in printf. The exclamation point is just the factorial symbol, as mentioned in the comment.






                    share|improve this answer
























                      2












                      2








                      2






                      %d and %ld are the formatting placeholders for int and long int in printf. The exclamation point is just the factorial symbol, as mentioned in the comment.






                      share|improve this answer












                      %d and %ld are the formatting placeholders for int and long int in printf. The exclamation point is just the factorial symbol, as mentioned in the comment.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 22 at 18:02









                      ahota

                      37128




                      37128























                          1














                          printf() allows you to print a string with variables inside of it. Let's say you have a variable i, containing an integer, 7.



                          printf("My variable is %d", i);


                          Will print



                          My variable is 7


                          to the console! That's because %d is how you tell printf(), "Hey, put an integer variable here!". The integer is then supplied as the next argument to the function. In your case, %d represents the integer n, and %ld represents the long integer f. Since f might be really big, we make it a long, which means more bytes are allocated to it internally on your computer. So for example, if we wanted to get the factorial of 5 and print it, we might do the following:



                          printf("Factorial of %d equals %ldn", 5, factorial(5))
                          // this will print "Factorial of 5 is 120" then a newline


                          Oh, and n just means print a newline afterwords!






                          share|improve this answer


























                            1














                            printf() allows you to print a string with variables inside of it. Let's say you have a variable i, containing an integer, 7.



                            printf("My variable is %d", i);


                            Will print



                            My variable is 7


                            to the console! That's because %d is how you tell printf(), "Hey, put an integer variable here!". The integer is then supplied as the next argument to the function. In your case, %d represents the integer n, and %ld represents the long integer f. Since f might be really big, we make it a long, which means more bytes are allocated to it internally on your computer. So for example, if we wanted to get the factorial of 5 and print it, we might do the following:



                            printf("Factorial of %d equals %ldn", 5, factorial(5))
                            // this will print "Factorial of 5 is 120" then a newline


                            Oh, and n just means print a newline afterwords!






                            share|improve this answer
























                              1












                              1








                              1






                              printf() allows you to print a string with variables inside of it. Let's say you have a variable i, containing an integer, 7.



                              printf("My variable is %d", i);


                              Will print



                              My variable is 7


                              to the console! That's because %d is how you tell printf(), "Hey, put an integer variable here!". The integer is then supplied as the next argument to the function. In your case, %d represents the integer n, and %ld represents the long integer f. Since f might be really big, we make it a long, which means more bytes are allocated to it internally on your computer. So for example, if we wanted to get the factorial of 5 and print it, we might do the following:



                              printf("Factorial of %d equals %ldn", 5, factorial(5))
                              // this will print "Factorial of 5 is 120" then a newline


                              Oh, and n just means print a newline afterwords!






                              share|improve this answer












                              printf() allows you to print a string with variables inside of it. Let's say you have a variable i, containing an integer, 7.



                              printf("My variable is %d", i);


                              Will print



                              My variable is 7


                              to the console! That's because %d is how you tell printf(), "Hey, put an integer variable here!". The integer is then supplied as the next argument to the function. In your case, %d represents the integer n, and %ld represents the long integer f. Since f might be really big, we make it a long, which means more bytes are allocated to it internally on your computer. So for example, if we wanted to get the factorial of 5 and print it, we might do the following:



                              printf("Factorial of %d equals %ldn", 5, factorial(5))
                              // this will print "Factorial of 5 is 120" then a newline


                              Oh, and n just means print a newline afterwords!







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 22 at 18:09









                              Alejandro Alvarado

                              18913




                              18913























                                  0














                                  printf("%d! = %ldn", n, f); //what does this mean?


                                  %d - print an integer as a signed decimal number.



                                  l - specifies that the argument is a long int or unsigned long int as appropriate. %ld then prints a long int or unsigned long int



                                  The printed text will become something like



                                  n! = f 


                                  (factorial notation n!)






                                  share|improve this answer


























                                    0














                                    printf("%d! = %ldn", n, f); //what does this mean?


                                    %d - print an integer as a signed decimal number.



                                    l - specifies that the argument is a long int or unsigned long int as appropriate. %ld then prints a long int or unsigned long int



                                    The printed text will become something like



                                    n! = f 


                                    (factorial notation n!)






                                    share|improve this answer
























                                      0












                                      0








                                      0






                                      printf("%d! = %ldn", n, f); //what does this mean?


                                      %d - print an integer as a signed decimal number.



                                      l - specifies that the argument is a long int or unsigned long int as appropriate. %ld then prints a long int or unsigned long int



                                      The printed text will become something like



                                      n! = f 


                                      (factorial notation n!)






                                      share|improve this answer












                                      printf("%d! = %ldn", n, f); //what does this mean?


                                      %d - print an integer as a signed decimal number.



                                      l - specifies that the argument is a long int or unsigned long int as appropriate. %ld then prints a long int or unsigned long int



                                      The printed text will become something like



                                      n! = f 


                                      (factorial notation n!)







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 22 at 18:32









                                      Andreas DM

                                      6,21352450




                                      6,21352450






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.





                                          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                          Please pay close attention to the following guidance:


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436191%2fwhat-does-d-ldn-mean-in-this-code%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Sphinx de Gizeh

                                          Dijon

                                          Équipe cycliste