Write a TCL program to get the numbers in the range (given in arguments) which are only divisible by 3 and 7.
Question
Write a TCL program to get the numbers in the range (given in arguments) which are only divisible by 3 and 7.
Solution
Sure, here is a simple TCL program that will print the numbers in a given range that are divisible by both 3 and 7.
proc divisible_by_3_and_7 {start end} {
for {set i $start} {$i <= $end} {incr i} {
if {$i % 3 == 0 && $i % 7 == 0} {
puts $i
}
}
}
# Call the function with the range you want to check
divisible_by_3_and_7 1 100
This program defines a procedure divisible_by_3_and_7 that takes two arguments: the start and end of the range to check. It then uses a for loop to iterate over each number in that range. If the current number is divisible by both 3 and 7 (i.e., the remainder when the number is divided by 3 or 7 is 0), it prints the number. Finally, it calls the procedure with the range 1 to 100. You can replace these numbers with any range you want to check.
Similar Questions
How many three digit numbers are there divisible by 7
write a tcl program to print all the numbers from 1 to 100.which is divisible by 4 and skip when its in 70's and 90's.
Mandy is a software engineer working on a program to analyze two integers based on specific conditions using a logical operator. She needs to determine if both integers are odd or if at least one of them is divisible by 7.Depending on the result, she wants to print different messages. If the condition is met, the program should identify and print the number that is first divisible by 7 or indicate that both numbers are odd.If the condition is not met, the program should print a message indicating the condition was not met along with the input numbers.Input format :The first line of input consists of an integer representing the first input number.The second line consists of an integer representing the second input number.
Take the last three digits of the number, double it, and subtract the result from the remaining part of the number is the divisibility rule for 7.Group of answer choicesTrueFalse
Find the least number when successively divided by 2,3, and 7 it leaves reminder 1,2, and 3 respectively.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.