answersLogoWhite

0


Best Answer

the for loop is basically a repitation or traversing loop means one's to write his name 100 times he use the for loop

example

for(i=0;i<=100;i++)

{

printf("my name is AA");

}

the for loop checks the condition until i<=100 repeates the name or check the condition upto 100 times and then terminates.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

A for loop is a loop of the form:

for (/*starting conditions/variable initialisation*/;/*condition*/;/*changes to variables*/) {}

The most basic example would be:

for (int i=0;i<10;i++) {

prinf("%i",i);

}

This code can be represented as the following algorithm:

  1. Let i=0
  2. If i>=10, go to step 6
  3. Write the value of i to the standard output stream
  4. Increment i (ie. i=i+1)
  5. Go to step 2
  6. End

The standard algorithm, for any 4 statements:

for (/*EXPRESSION 1*/;/*EXPRESSION 2*/;/*EXPRESSION 3*/) {

/*STATEMENT 4*/

}

would be:

  1. EXPRESSION 1
  2. If EXPRESSION 2 is false go to step 6
  3. STATEMENT 4
  4. EXPRESSION 3
  5. Go to step 2
  6. End
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the algorithm for a for loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Must a computer algorithm contain a loop?

No. An algorithm is a procedure or formula for solving a problem: a finite series of computation steps to produce a result. Some algorithms require one or more loops, but it is not true that every algorithm requires a loop.


How can I proof about correctness of Square-and-multiply algorithm?

Using loop invariant.


C program algorithm for simple interest using while loop?

Not used


Write a algorithm for multiplication tabel for an integer?

Algorithm: 1. From the user collect the integer whose table is required 2. Use a loop with loop counter starting with 0x01 and ends till the table value is required 3. start multiplication the input number with the loop variable and print the result.


How is time complexity of an algorithm calculated?

The usual definition of an algorithm's time complexity is called Big O Notation. If an algorithm has a value of O(1), it is a fixed time algorithm, the best possible type of algorithm for speed. As you approach O(&acirc;&circ;&#382;) (a.k.a. infinite loop), the algorithm takes progressively longer to complete (an algorithm of O(&acirc;&circ;&#382;) would never complete).


In the bubble sort algorithm the second loop iterates ---------- for each of the unsorted array elements?

n-1 times


Write an algorithm or draw a flowchart to display numbers from 100 down to 10?

n=100 loop until n = 9 print n n = n -1 end loop


C program find magic number less than 1000?

#define int main (void){/*Algorithm*/1. First Initialize the number that is Random no2. Using while loop if the person got it, then the loop stop if not the loop continues.}return(0);


How do you get the square roots using algorithm?

An algorithm is process or set of rules for doing something If we are looking for square rots which are integers then an algorithm might look like this Put the number whose root is sought into a variable - the dividend. Put 2 into a variable - the divisor Begin a loop divide the dividend by the divisor put the result into a variable - the quotient if the quotient = the divisor then the quotient is the square root of the divident else, add 1 to the divisor next loop


What are the 3 primitive logic structures?

The three primitive logic structures in programming are selection, loop and sequence. Any algorithm can be written using just these three structures.


Why is dijkstra's algorithm not suitable for distributed applications with large number of distributed nodes?

"OSPF detects changes in the topology, such as link failures, very quickly and converges on a new loop-free routing structure within seconds. It computes the shortest path tree for each route using a method based on Dijkstra's algorithm, a shortest path first algorithm."


How can you find the LCM in c without using any loop and condition?

The LCM can be calculated without using any loop or condition as follows: int lcm (int a, int b) { return a / gcd (a, b) * b; } The problem is that the typical implementation for the GCD function uses Euclid's algorithm, which requires a conditional loop: int gcd (int a, int b) { while (b!=0) b ^= a ^= b ^= a %= b; return a; } So the question is really how do we calculate the GCD without a conditional loop, not the LCM. The answer is that we cannot. There are certainly alternatives to Euclid's algorithm, but they all involve conditional loops. Although recursion isn't technically a loop, it still requires a conditional expression to terminate the recursion.