Skip to main content

find Armstrong number in php

find  Armstrong number in php
 <?
     armstrong(9999);
     function armstrong($maximum_number)
     {
         $sum=0;
         print("Armstrong numbers between 0 to $maximum_number are: ");
   
         for($i=0; $i<=$maximum_number; $i++)
         {
             $num=$i;
             $sum=0;
             $len=strlen($i); //Length of number i.e number of digits in a number
             while($num>0)
             {
                $rem=$num%10;
                $power=pow($rem,$len);//Raise to the power of length of each digit in a number.
                $sum=$sum+$power; //Sum of power of all digits of a number
                $num=$num/10; // Calculate next number
             }
             if($sum==$i)
             {
                 echo $i . "= Yes <br/>";
              }          
          }      
      }
      ?>


 <?
     armstrong(9999);
     function armstrong($maximum_number)
     {
         $sum=0;
         print("Armstrong numbers between 0 to $maximum_number are: ");
    
         for($i=0; $i<=$maximum_number; $i++)
         {
             $num=$i;
             $sum=0;
             $len=strlen($i); //Length of number i.e number of digits in a number
             while($num>0)
             {
                $rem=$num%10;
                $power=pow($rem,$len);//Raise to the power of length of each digit in a number.
                $sum=$sum+$power; //Sum of power of all digits of a number
                $num=$num/10; // Calculate next number
             }
             if($sum==$i)
             {
                 echo $i . "= Yes <br/>";
              }           
          }       
      }
      ?>

Comments

Popular posts from this blog

Minimum and maximum number with - and + 500 in Mysql and Sql query and Find out table scheema of our database in Mysql and sql query and Find out all table name of our database in Mysql and sql query and Find out current date and time in mysql and sql help of sql query

Minimum and maximum number with - and + 500 in Mysql and Sql query:- syntax:-  SELECT MIN(Used)-500 , max(Used)+500 FROM audit Find out current date and time in mysql and sql help of sql query:- syntax:- SELECT now() Find out database name in Mysql and sql query:- syntax:-  SELECT DATABASE(); Find out all table name of our database in Mysql and sql query:- syntax:- SHOW TABLES; Find out   table scheema   of our database in Mysql and sql query:- syntax:- DESCRIBE <table name>;

PHP STRING FUNCTION WITH OUTPUT AND EXAMPLE

PHP STRING FUNCTION  WITH OUTPUT AND EXAMPLE  <?php   $var="my name is saddam hussain saifi ";   print_r(explode("a",$var)); //output:Array ( [0] => my n [1] => me is s [2] => dd [3] => m huss [4] => in s [5] => ifi )       echo crypt($varws);//output:-$1$m5/.1//.$KRawtTgnzzScShDJN3aHa.     echo crc32($var);//output:-1732983884  echo count_chars($var ,4);//output;-!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`bcgjklopqrtvwxz{|}~€ ‚ƒ„…†‡ˆ‰Š‹Œ Ž ’“”•–—˜™š›œ žŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ    echo convert_uuencode($var);//output:-@;7D@;F%M92!I      echo convert_uudecode($var);// output:d4P L@M     echo convert_cyr_string($var,'m','a');       echo chunk_split($var,2,"(sam)");//output:-my(sam) n(sam)am(sam)e (sam)is(sam) s(sam)ad(sam)da(sam)m (sam)hu(sam)ss(sam)ai(sam)n (sam)s...

Fetching data into mysql AND php

LIST DATA FROM MYSQL TABLE USED PHP <html> <head> <title>php and mysql by sam saifi</title> </head> <body> Fetching data into mysql table on localhost step by step step1:- create connection to data  like $con. step2:-select database like $db. step3:- write query like $sql. step4:-fetching  data in loop like while loop step5:- create object in loop like $row. step6:-execute object with table colum name like $row['name']; <? $con = mysql_connect("localhost","sam","") or die(mysql_error());// here  sam is  user name $db = mysql_select_db("sam");//here sam is data base name $sql = "SELECT * FROM cust"; $query = mysql_query($sql) or die ("error Query [".$sql."]"); ?> <table   >   <tr>     <th  > <div >id </div></th>     <th  > <div >name </div></th>     <th  > <div >e-mail </div...