29. Write a program to test whether a given number is divisible by another given number.
30. Write a program to print cubes of first 15 natural numbers.
please give the program
Answers
29.
dvd = int(input("Enter the dividend: "))
dvr = int(input("Enter the divisor: "))
if dvd%dvr == 0:
print(dvd, "is divisible by", str(dvr) + ".")
else:
print(dvd, "is not divisible by", str(dvr) + ".")
We input the dividend and divisor and then use conditional statements to test the divisibility of the two numbers.
30.
for i in range(1, 16):
print(i**3)
We use an iteration statement that traverses through the given range and prints the required data.
Answer:
This answer is written using JAVA programming
Question 29:
//To check if number is divisible by other number or not
package Programmer;
//it is an optional statement,no need to write.
import java.util.Scanner;
public class DivisiblityCheck{
public static void main (String ar []){
Scanner sc=new Scanner (System.in);
System.out.println("Enter dividend");
int a=sc.nextInt();
System.out.println("Enter divisor");
int b=sc.nextInt();
if ( a%b==0)
System.out.println("Divisible");
else
System.out.println("Not Divisible");
}
}
__
Question 30:
//Program to print first 15 cubes of natural numbers
public class Cube{
public static void main (String ar []){
for(int I=1;I<=15;I++)
System.out.println(Math.pow(I,3));
//You can also write (I*I*I) instead of Math.pow()
}
}