WAP to input a number and find its odd factors.
Answers
Answered by
3
The given problem is solved using language - Java.
import java.util.*;
public class OddFactors{
public static void main(String s[]){
Scanner sc=new Scanner(System.in);
int n,i;
System.out.print("Enter a number: ");
n=sc.nextInt();
sc.close();
System.out.print("The odd factor(s) of the number is/are: ");
for(i=1;i<=n;i+=2){
if(n%i==0)
System.out.print(i+" ");
}
}
}
- Here the loop iterates from i = 1 to n. If the number (n) is divisible by 'i', then the value of the variable 'i' is displayed.
- After each iteration, the value of 'i' is incremented by 2 as we have to display only the odd factors of the number.
See attachment for output.
Attachments:
anindyaadhikari13:
Thanks for the Brainliest :)
Similar questions
Math,
1 month ago
Physics,
2 months ago
Business Studies,
10 months ago
English,
10 months ago
Math,
10 months ago