Problem in Code

i'm making a code in which user will give input and it will return multiplication
for example if user give input "6" it should return "720" because 6*5*4*3*2*1 = 720
please correct the below code
hope you understand if not then comment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
#include<conio.h>

int main()
{
clrscr();
int a=0;
int d=0;
printf("Enter any Number"); scanf("%d",a);

for(int b=1;b<=a;b++)
  {
   for(int c=2;c<a;c++)
    {
    d=a*c;
    }
   }
   printf("%d",d);
   getch();
   }
Hi,
Try this :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a, b, c = 0;
printf("Enter any Number");
scanf("%d", &a);
b = a;
for(int i = a; i >= 1; i--)
  {
     if(!c) c = b; else c *= b;
     b--;
  }
   printf("%d", c);
   getch();
   }
Last edited on
Does that help you? :)
yes it helped thank you soo much bro :-)
can you please explain the codes i mean how is it working?
i've never learnt this can you explain?
1
2
3
4
{
     if(!c) c = b; else c *= b;
     b--;
  }
Topic archived. No new replies allowed.