Loops (Factorial Calculation)
LOOPS (Height of Pyramid)
Initialize
Select Loop Type
Enter number for calculating P!
Step Execution
int main(){
 int p;
 int fact=1;
 if(p==0)
 {
  return 1;
 }
 for(int i=p;i>=1;i--)
 {
   fact=fact*i;
 }
 return fact;
}
int main(){
 int p;
 int fact=1;
 if(p==0)
 {
   return 1;
 }
 while (i>=1)
 {
  fact=fact*i;
  i--;
 }
 return fact;
}
int main(){
 int p;
 int fact=1;
 int i=p;
 if(p==0)
 {
  return 1;
  }
 do
 {
  fact=fact*i;
   i--;
  }while(i>=1);
}
int main(){
int i,j,k;
int height;
for (i=0;i<height;i++)
{
for(j=0;j<height-i-1;j++)
{
printf(" ");
}
for(k=j;k<height-1;k++)
{
printf("*");
printf(" ");
}
printf("*");
for(j=0;j<height-i-1;j++)
{
printf(" ");
}
printf("\n");
}
return 0;
}
Code Output
Local Variables :
i :
fact :
i :
j :
k :