Tell me whats wrong in this code used to calculate factorial

#include <iostream.h>
using namespace std;

int main() {
int t,n;
for(int i=0;i<t;i++){
int sum=1;

The library is only ‘iostream’ not ‘iostream.h’ . So instead of #include<iostream.h> use #include
It is also wrong . It will be n --; or n=n-1;
and one last thing there is one closed curly bracket missing for the int main () so that to you had to also add in the end .

It should be n-- instead of n- on line 15.

This is just the result of the poster not formatting their code.


Oh no - this is going to be a repeat of this thread again, isn’t it? XD

Who will be the first person to mention integer overflow?

1 Like

i) #include
ii) n–; (n minus minus. It is decrement operator.)

/Mention what to input. Before cin>>t, cout<<“Type how many times you want to calculate factorial”. This helps the user. Also use return 0; since the main function is not returning any value/