-1

I'm trying to run a factorial programme in c using cmd using DOS shell in turbo c7. The code is:

#include<stdio.h>
void main(int argc, char* argv[])
{
    int i, n, fact = 1;
    n = atoi(argv[1]);
    for (i = 1; i <= n; i++)
    {   
        fact = fact * i;
    }
    printf("Factorial is:%s\n",fact);
}

when I run it as fact.exe 3 The o/p is= factorial is:rland c++ -copyright 1991 borland Intl. What should I do?

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
Aishwarya
  • 19
  • 1
  • 1
  • 3
  • 2
    And what problem do you have with the program? What happens when you build it? What happens when you run it? You should really take some time to [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). Perhaps all you need is to read [a couple of good beginners books](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list)? – Some programmer dude Sep 25 '17 at 14:13
  • You try to print number but you set string `printf("Factorial is:%s\n",fact); = > printf("Factorial is:%d\n",fact);` – Ivan Sheihets Sep 25 '17 at 14:16

1 Answers1

3

You want to print a number, not a string, thus your format string is incorrect.

Change printf("Factorial is:%s\n",fact); to printf("Factorial is:%d\n",fact);.

MarkWeston
  • 740
  • 4
  • 15