what will be the output of print 17mod 5.please correct answer nedded
Share
what will be the output of print 17mod 5.please correct answer nedded
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer:
You might have noticed that many programming problems ask you to output the answer “modulo 1000000007 (10^9 + 7)”. In this note I’m going to discuss what this means and the right way to deal with this type of questions. So, here it is...
First of all, I’d like to go through some prerequisites.
The modulo operation is the same as ‘ the remainder of the division ’. If I say a modulo b is c, it means that the remainder when a is divided by b is c. The modulo operation is represented by the ‘%’ operator in most programming languages (including C/C++/Java/Python). So, 5 % 2 = 1, 17 % 5 = 2, 7 % 9 = 7 and so on.
Answer:
class JavaExample
{ public static void main(String args[]) {
int n = 30;
System.out.print("Odd Numbers from 1 to "+n+" are: ");
for (int i = 1; i <= n; i++) {
if (i % 2 != 0) {
System.out.print(i + " ");
}
}
}
}