हिंदी

Given below is the program with errors in it. Identify the errors. Rewrite the program and predict the output. import java.util.*; class ProGram { void main() { int n=0, tn = 0, p = 0; Scanner

Advertisements
Advertisements

प्रश्न

Given below is the program with errors in it. Identify the errors. Rewrite the program and predict the output.

import java.util.*;
class ProGram
{
      void main()
      {
         int n=0, tn = 0, p = 0 ; Scanner sc = new Scanner (System.in);
         System.out.print("\n Enter total terms (n) :");n = sc.nextInt();
         for(tn = n; tn<=1; tn--)
         {
             p =p*tn;
             System.out.print("Factorial of n =" + p );
         }
      }
}
कोड लेखन
Advertisements

उत्तर

import java.util.*;
class ProGram
{
    void main()
    {
      int n=0, tn = 0, p = 1; Scanner sc=new Scanner(System.in);
      System.out.print("\n Enter total terms (n):");n=sc.nextInt();
      for(tn = n; tn>= 1; tn--)
      {
          p=p*tn;
      }
      System.out.print("Factorial of n ="+p);
    }
}

Factorial of n

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 1: Revision of Class 9 Syllabus - Exercises [पृष्ठ ४८]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 1 Revision of Class 9 Syllabus
Exercises | Q 6. (v) | पृष्ठ ४८
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×