0

i am trying to print multiplication table by using for loop but it is showing only the last one instead of displaying all. :(

#include <iostream>

using namespace std;

int main()
{
   int i,j, k;
   cout<< "enter i value";
   cin>> i;
   for(j=0;j<20;j++)
   k=i*j;
   cout<< k <<endl;

   return 0;
}

Edited by Srinivas0: n/a

2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by frogboy77
0

{} braces around your loop

ah its working now. so whats the diff between both ? cause the program complied without the braces as well. :-/

0

Without the braces the loop only executes the one command after then exits after it has finished, then you output the final value of k.

Edited by frogboy77: n/a

0

Without the braces the loop only executes the one command after then exits after it has finished, then you output the final value of k.

got it thx for the fast reply dude.:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.