Computer Science, asked by moongully6360, 9 months ago

.WRITE AN ALGORITHM TO INPUT 3 NUMBERS , DISPLAY ONLY THOSE NUMBERS WHICH ARE DIVISIBLE BY 8.

Answers

Answered by saranr
1

Answer:

C++

// C++ program to print all the numbers  

// divisible by 3 and 5 for a given number  

#include <iostream>  

using namespace std;  

 

// Result function with N  

void result(int N)  

{      

   // iterate from 0 to N  

   for (int num = 0; num < N; num++)  

   {      

       // Short-circuit operator is used  

       if (num % 3 == 0 && num % 5 == 0)  

           cout << num << " ";  

   }  

}  

 

// Driver code  

int main()  

{      

   // input goes here  

   int N = 100;  

     

   // Calling function  

   result(N);  

   return 0;  

}  

 

 

java

// Java program to print all the numbers  

// divisible by 3 and 5 for a given number  

 

class GFG{  

     

   // Result function with N  

   static void result(int N)  

   {      

       // iterate from 0 to N  

       for (int num = 0; num < N; num++)  

       {      

           // Short-circuit operator is used  

           if (num % 3 == 0 && num % 5 == 0)  

               System.out.print(num + " ");  

       }  

   }  

       

   // Driver code  

   public static void main(String []args)  

   {  

       // input goes here  

       int N = 100;  

           

       // Calling function  

       result(N);  

   }  

}  

python

# Python program to print all the numbers  

# divisible by 3 and 5 for a given number  

 

# Result function with N  

def result(N):  

     

   # iterate from 0 to N  

   for num in range(N):  

         

           # Short-circuit operator is used  

           if num % 3 == 0 and num % 5 == 0:  

               print(str(num) + " ", end = "")  

                 

           else:  

               pass

 

# Driver code  

if __name__ == "__main__":  

     

   # input goes here  

   N = 100

     

   # Calling function  

   result(N)  

C#

// C# program to print all the numbers  

// divisible by 3 and 5 for a given number  

using System;  

public class GFG{  

     

   // Result function with N  

   static void result(int N)  

   {      

       // iterate from 0 to N  

       for (int num = 0; num < N; num++)  

       {      

           // Short-circuit operator is used  

           if (num % 3 == 0 && num % 5 == 0)  

               Console.Write(num + " ");  

       }  

   }  

     

   // Driver code  

   static public void Main (){  

       // input goes here  

       int N = 100;  

       // Calling function  

       result(N);  

   }  

}

PHP

<?php  

// PHP program to print all the numbers  

// divisible by 3 and 5 for a given number  

 

// Result function with N  

function result($N)  

{  

   // iterate from 0 to N  

   for ($num = 0; $num < $N; $num++)  

   {  

       // Short-circuit operator is used  

       if ($num % 3 == 0 && $num % 5 == 0)  

           echo $num, " ";  

   }  

}  

 

// Driver code  

     

// input goes here  

$N = 100;  

 

// Calling function  

result($N);  

 

?>  

Similar questions