Factorial Program in Angular Framework

0
First Create a Component using 

ng g c fact

After Create HTML Page
<p>factapp works!</p>

<input type="text" name="a" [(ngModel)]="a" />
<br><br>
<input type="button" name="btnclick" value="Click" (click)="factorial()">
<br>

<div [innerHTML]="f"></div>

Create a TypeScript:-

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-factapp',
  templateUrl: './factapp.component.html',
  styleUrls: ['./factapp.component.css']
})
export class FactappComponent implements OnInit {
  a=5
  f=1
  i=1
  s=''
  constructor() {

   
  }

  ngOnInit() {
  }
  factorial()
  {
   
   
     for(this.i=1;this.i<=this.a;this.i++)
      {
         this.f=this.f*this.i

      }
  }
}

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)