Write a BASIC program in GW BASIC to input a number. Print all the factors of the number. (I read in Class 7) DO NOT WRITE ABSURD OR CONFUSING answers as such answers will be immediately reported.
Answers
Answer:
import java.util.Scanner; // Importing the Scanner Class
Class Program{ // You Can Give Your Class Name Accordingly
public static void main(){
Scanner sc=new Scanner(System.in); // Creating the Scanner Class
System.out.println("Enter any Number:");
int n=sc.nextInt();
int i;
// This is the Main Part of the Program which You Should Consider and Understand it Properly
for(i = 1; i <= n; i++) {
if(n%i == 0) {
System.out.println(i);
}
}
}
Explanation:
This is Well An Easy Program But You Should Understand it Clearly to Increase Your Programming Skills.
When the Main Part of the Program that is the For Loop Executes, it Run the Loop Until the Nunber itself Stored in Variable 'n' of integer type..
if n is totally divisible by i that is the Number from 1 to the Number it Runs and then if the Condition is True it Prints the Following Number that is Stored under Variable 'i'.
---------------------------
HOPE IT HELPS
FOR ANY QUERY PLEASE COMMENT DOWN BELOW...