You can use recursion:
void printNum(int i)
{ if(i <= 100)
{ printf("%d\n", i);
printNum(i + 1); } }
int main()
{
printNum(1);
return 0;
}
#include <stdio.h> void main () { static int i = 0; i++; printf("%d ", i); if( i != 100 ) main(); }
n=100 loop until n = 9 print n n = n -1 end loop
You need a code that can run to print even numbers between 10 and 100 using the qbasic command.
Loop through some numbers - for example, 2 through 100 - and check each one whether it is a prime number (write a second loop to test whether it is divisible by any number between 2 and the number minus 1). If, in this second loop, you find a factor that is greater than 1 and less than the number, it is not a prime, and you can print it out.
I'm not sure that HTML can do this, you should look into a web scripting language like php or javascript. In C it is trivial: int main() { for(int i = 1; i < 100; i++) printf("%d\n", i); return 0; }
int i, sum; /* example using while */ sum = 0; i = 1; while (i <= 100) { sum += i; ++i; } /* example using for */ sum = 0; for (i = 1; i <= 100; ++i) sum += i;
The best way to print the numbers 1 to 100 in PHP without using a loop is with the following code: echo implode("<br>", range(1,100)); You can replace the <br> with anything that you want to separate the numbers, such as dashes. I used a line-break in the example.
printf ("%s\n", "1, 2, 3, 4, 5, 6, ..., 98, 99, 100"); printf ("%s\n", "100, 99, 98, 97, ..., 3, 2, 1");
c the book mastering c
A for loop is typically used to implement a counted loop: for x=0 to 100 step 1 print x next x
n=100 loop until n = 9 print n n = n -1 end loop
If you mean you cannot use a for loop, then use a while loop: int i=0 while( i++ < 100 ) std::cout << i << " "; std::cout << std::endl; Or a do-while loop: int i=0; do std::cout << ++i << " "; while( i<100 ); std::cout << std::endl; If these are not allowed either, use a procedural loop: int i=0; again: std::cout << ++i << " "; if( i<100 ) goto again; std::cout << std::endl; If even that is not allowed, then the only option is to hard-wire: std::cout << 1 << " " << 2 << " " << [etc] << 99 << " " << 100 << std::endl; It does seem a pointless exercise when a for loop exists specifically for counting iterations like this: for( int i=1; i<=100; ++i ) std::cout << i << " "; std::cout << std::endl;
A loop is used in programming to repeat a set of commands in the program when a task is a repetitive one. It means less code has to be written and it makes a computer more flexible. If you wanted to do something like print all the numbers from 1 to 100 on the screen, you could do it with a loop. One way is to do 100 separate commands to print each number which is a long way. That will make your program quite long. With a loop you can use the command to print a number and tell it to do that command 100 times and increase the number being printed by 1 every time the command is run.
start n=1,0 print n n>=99,100 yes end no n=n+2 back to print step
recu
Use a counted loop in the closed range [1:100]. If the count is in the closed range [40:50], print the number. For all other numbers outwith this range, only print the number if it is prime.
You need a code that can run to print even numbers between 10 and 100 using the qbasic command.
RANDOMIZE TIMER rndNumber% = INT(RND * 100) + 1 winFlag% = 0 CLS PRINT "PROGRAM: Guess the number" PRINT PRINT "I'm thinking of a number between: 1-100. You've 7 guesses..." PRINT PRINT "Guess No" FOR eachGuessNo% = 1 TO 7 PRINT eachGuessNo%; "> "; INPUT "What is my number"; guessNum% IF guessNum% = rndNumber% THEN PRINT "Yes, correct guess; you WIN!" winFlag% = 1 EXIT FOR END IF NEXT IF winFlag% = 0 THEN PRINT "No, you guessed WRONG! I the computer WIN!" PRINT "My number was: "; rndNumber% PRINT PRINT "Again, Y/N"; yesNo$ DO yesNo$ = INKEY$ LOOP UNTIL yesNo$ <> "" IF UCASE$(LEFT$(yesNo$, 1)) = "Y" THEN RUN END