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;
}

{} braces around your loop

{} braces around your loop

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

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.

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.:)

so big me up

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.