Posts

ARMSTRONG, PRIME

 PRIME NO : <!DOCTYPE html> <html> <head>     <meta charset="utf-8">     <meta name="viewport" content="width=device-width, initial-scale=1">     <title> TAKE A NUM FIND THE FACTORIAL OF A GIVEN NO USING PROMPT</title> </head> <body>     <script type="text/javascript">         a= parseInt(prompt("Prime No Checker: ")); // set count as 0 c=0 // if given no is positive if(a>0){     // Loop checking divisability     for(i=1;i<=a;i++){         if(a%i==0){             c=c+1;         }     }     // count set to 2 when it is divided by 1 and itself     if(c==2){         document.write(`Given No ${a} is Prime No.`);                }     else{         document.write(`Given No ${a} is Not a Prime No.`);     } }else if(a==0){     document.write(`Given No ${a} is Not a Prime No.`); }else{     document.write(`Please Enter Unsigned No. `); }     </script> </body> </html&

PROMPT CALCULATOR SWAP LARGEST SMALLEST FACTOR FACTORIAL AND SUM OF SERIES PROGRAM

 SUM OF SERIES : document.write("it works Sum of series 1 2 3 4 5<br>"); var sum = 0; [1,2,3,4,5].forEach(function(number) {   sum += number; }); document.write("SUM= "+sum +"<br>"); FACTORIAL: <!DOCTYPE html> <html> <head><title> </title></head> <style type="text/css"> *{     background: #d2d5d8 ;      }    h1{     display: flex;     justify-content: center;     align-items: center; } ::selection{   background-color: #dddd2a;color:black;} </style> <body><h1>     <script type="text/javascript">         a= parseInt(prompt("Find Factorial: ")); // set factorial ans f as 1 f=1; // if given no is positive if(a>0) {     // decrementing loop     for(i=a;i>0;i--){         f= f * i;        }     document.write(`The Factorial of ${a} is ${f}`); }else if(a==0){     document.write(`The Factorial of 0 is 1`);    } else{     document.write(`Please Enter Uns

BUBBLE SORT

 Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. Example:   First Pass:   ( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1.  ( 1 5 4 2 8 ) –>  ( 1 4 5 2 8 ), Swap since 5 > 4  ( 1 4 5 2 8 ) –>  ( 1 4 2 5 8 ), Swap since 5 > 2  ( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm does not swap them. Second Pass:   ( 1 4 2 5 8 ) –> ( 1 4 2 5 8 )  ( 1 4 2 5 8 ) –> ( 1 2 4 5 8 ), Swap since 4 > 2  ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )  ( 1 2 4 5 8 ) –>  ( 1 2 4 5 8 )  Now, the array is already sorted, but our algorithm does not know if it is completed. The algorithm needs one whole pass without any swap to know it is sorted. Third Pass:   ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )  ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )  ( 1 2 4 5 8 ) –> ( 1 2 4

Python Program to Find HCF or GCD

  Python Program to Find HCF or GCD In this example, you will learn to find the GCD of two numbers using function and loop. The highest common factor (H.C.F) or greatest common divisor (G.C.D) of two numbers is the largest positive integer that perfectly divides the two given numbers. For example, the H.C.F of 12 and 14 is 2. Source Code: Using Loops    # Python program to find H.C.F of two numbers # define a function def compute_hcf(x, y): # choose the smaller number if x > y: smaller = y else: smaller = x for i in range(1, smaller+1): if((x % i == 0) and (y % i == 0)): hcf = i return hcf num1 = int(input("Enter the first number: ")) num2 = int(input("Enter the second number: ")) print("The H.C.F. is", compute_hcf(num1, num2))    Output: D:\PROGRAMMING\PYTHON>python Hcf.py Enter the first number: 8 Enter the second number: 12 The H.C.F. is 4 D:\PROGRAMMING\PYTHON>python Hcf.py Enter the fi

Python Program to Find the Factors of a Number

  Python Program to Find the Factors of a Number   # Python Program to find the factors of a number # This function computes the factor of the argument passed l=[] # To store values list is used def print_factors(x): print("The factors of",x,"are:") for i in range(1, x + 1): if x % i == 0: l.append((i,x/i)) return l num = int(input("Enter the number: ")) print(print_factors(num))   Output: Enter the number: 320 The factors of 320 are: [(1, 320.0), (2, 160.0), (4, 80.0), (5, 64.0), (8, 40.0), (10, 32.0), (16, 20.0), (20, 16.0), (32, 10.0), (40, 8.0), (64, 5.0), (80, 4.0), (160, 2.0), (320, 1.0)]  Note: To find the factors of another number, change the value of num . In this program, the number whose factor is to be found is stored in num , which is passed to the print_factors() function. This value is assigned to the variable x in print_factors() . In the function, we use the for loop to iterate from i equal to x . If x is perfectly divisi

TABLE GENERATOR USING JAVASCRIPT

TABLE GENERATOR USING JAVASCRIPT   <script type="text/javascript"> </script> <script type="text/javascript"> // fACTOR 12 = 1,2,3,4,6, AND 12 function check() {   var number= document.getElementById('n1').value; var number2= document.getElementById('n2').value; var str2="";     for (var j=parseInt(number); j<= parseInt(number2); j++)     {          var str="";         for (var i=1; i<=10; i++)         {         str = str + `${j*i}  `;         }     str2= str2 + '\n'+ str;        console.log(str2);     } document.getElementById('tav').innerText=`${str2}`; } </script> <br> <input type="number" name="" id="n1"> <input type="number" name="" id="n2"> <br> <button onclick="check()">GENERATE</button> <h3 id="tav"> </h3>

GREATEST COMMON FACTOR

  Write a program in python to calculate greatest common divisor of a number   import math print("Greatest Common Divisor ")   # prints 12 print("The gcd of 60 and 48 is : ", end="") print(math.gcd(60, 48)) # The gcd of 98 and 56 is : 14 # The gcd of 60 and 48 is : 12 ''' def hcf(a, b):     if(b == 0):         return a     else:         return hcf(b, a % b)   a = 60 b = 48   # prints 12 print("The gcd of 60 and 48 is : ", end="") print(hcf(60, 48)) '''