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
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.
write a program that performs bitwise AND between 7 and the number given by Alice and prints the result.
Write a program to sort integers in ascending order. Input is passed in TCL file argument.
How many integers between 1 and 7 000, including both 1 and 7000, are divisible by 2, 5, and 7?
Which of the number is divisible by 3,7 and 9 all three?Options :4725463846514598
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.