7 Replies - 607 Views - Last Post: 22 December 2013 - 06:54 AM Rate Topic: -----

#1 king hero  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-December 13

code of the multiplication tables Pyramid

Posted 19 December 2013 - 10:45 AM

i want this

cout

72 60 48 36 24 12
55 44 33 22 11
40 30 20 10
27 18 9
16 8
7
6
4 10
4 8 12
3 6 9 12
2 4 6 8 10
1 2 3 4 5 6

but this is my code " i think Wrong now what's right "

#include<stdio.h>
void main()
{
int i,j;
clrscr();

 for(i=12;i<=6;i--)
  {
       for(j=1;j<=i;j++)
       {
       printf("%d\t",i*j);
       }
   printf("\n");
  }
getch();
}

This post has been edited by modi123_1: 19 December 2013 - 10:48 AM
Reason for edit:: fixed botched code tags


Is This A Good Question/Topic? 0
  • +

Replies To: code of the multiplication tables Pyramid

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8955
  • View blog
  • Posts: 33,571
  • Joined: 12-June 08

Re: code of the multiplication tables Pyramid

Posted 19 December 2013 - 10:48 AM

Quote

but this is my code " i think Wrong now what's right "

You think it is wrong? Why is that?
Was This Post Helpful? 0
  • +
  • -

#3 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 651
  • View blog
  • Posts: 2,231
  • Joined: 31-December 10

Re: code of the multiplication tables Pyramid

Posted 19 December 2013 - 10:54 AM

First, why don't you write out a formula that will match what is supposed to be printed? For example, that isn't the exact multiplication table. The first line is 12 * 6, 12 * 5, 12 * 4, ..., 12 * 1. The next line is 11 * 5, 11 * 4, ..., 11 * 1, and the third is 10 * 4, ..., 10 * 1.

But once you get to lines 6 and 7, after that it changes just slightly. Line 8 is 4 and 10, whats the formula to figure that out? Then the next line is 4, 8, and 12.

I'm not 100% sure, but I think you might need to 2 outer loops to do "both" triangles. The key is to figure out the formula(s) to use.

*EDIT*:
Should line 8 be 5 and 10 and not 4 and 10?

This post has been edited by vividexstance: 19 December 2013 - 10:55 AM

Was This Post Helpful? 0
  • +
  • -

#4 king hero  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-December 13

Re: code of the multiplication tables Pyramid

Posted 19 December 2013 - 04:09 PM

View Postmodi123_1, on 19 December 2013 - 10:48 AM, said:

Quote

but this is my code " i think Wrong now what's right "

You think it is wrong? Why is that?



just feeling

View Postvividexstance, on 19 December 2013 - 10:54 AM, said:

First, why don't you write out a formula that will match what is supposed to be printed? For example, that isn't the exact multiplication table. The first line is 12 * 6, 12 * 5, 12 * 4, ..., 12 * 1. The next line is 11 * 5, 11 * 4, ..., 11 * 1, and the third is 10 * 4, ..., 10 * 1.

But once you get to lines 6 and 7, after that it changes just slightly. Line 8 is 4 and 10, whats the formula to figure that out? Then the next line is 4, 8, and 12.

I'm not 100% sure, but I think you might need to 2 outer loops to do "both" triangles. The key is to figure out the formula(s) to use.

*EDIT*:
Should line 8 be 5 and 10 and not 4 and 10?



all you say is right ...

but this is my code

#include <iostream>
using namespace std;
 
int main() {
   int size = 6;
   for (int row = 1; row <= size; --row) {     // Outer loop to print all the rows
      for (int col = 1; col <= size; ++col) {  // Inner loop to print all the columns of each row
         cout << "A multiplication table:" << endl
          << "  12\t11\t10\t9\t8\t7\t6\t5\t4\t3\t2\t1" << endl
          << "" << endl;
     for(int c = 1; c < 13; c--)
     {
          cout << c << "    ";
          for(int i = 1; i < 13; i++)
          {
          cout << i * c << '\t';
          }
      cout << endl;   // A row ended, bring the cursor to the next line
   }
 
   return 0;
}


and i don't know the mistake
Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg  Icon User is offline

  • member icon


Reputation: 3993
  • View blog
  • Posts: 12,323
  • Joined: 25-December 09

Re: code of the multiplication tables Pyramid

Posted 19 December 2013 - 04:37 PM

Quote

and i don't know the mistake

Does the code you provided compile without errors or warnings?

If not post the complete error messages exactly as they appear in your development environment.

If so what exactly is wrong with your program?

Does it produce any output?

If so show us that output.

Otherwise describe exactly what your program is doing.


Jim
Was This Post Helpful? 0
  • +
  • -

#6 king hero  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-December 13

Re: code of the multiplication tables Pyramid

Posted 21 December 2013 - 11:11 AM

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    cout<<"welcome belal";
    cout<<"please enter the number of the rows";
    int m;
    cin>>m;
    for(int x=m/2;x>=1;x--)
    {
       for(int y=x;y>=1;y--)
       
       cout<<(x*2)*y ;
       cout<<endl;
       }
       for(int x=1;x<=m/2;x++)
       {
               for(int y=1;y<=x;y++)
               cout<<(y*2)*x ;
               cout<<endl;
               }      
                        
    system("PAUSE");
    return EXIT_SUCCESS;
}



but the cout not like i want

72 60 48 36 24 12
55 44 33 22 11
40 30 20 10
27 18 9
16 8
7
6
4 10
4 8 12
3 6 9 12
2 4 6 8 10
1 2 3 4 5 6
Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is offline

  • member icon


Reputation: 3993
  • View blog
  • Posts: 12,323
  • Joined: 25-December 09

Re: code of the multiplication tables Pyramid

Posted 21 December 2013 - 11:22 AM

What output are you getting?

What did you input into your program?

Jim

This post has been edited by jimblumberg: 21 December 2013 - 11:23 AM

Was This Post Helpful? 0
  • +
  • -

#8 tarmizi_adam2005  Icon User is offline

  • جوروترا

Reputation: 224
  • View blog
  • Posts: 801
  • Joined: 18-April 09

Re: code of the multiplication tables Pyramid

Posted 22 December 2013 - 06:54 AM

Hi,

I think if you input different values to your program you will definitely get different output. The closest to what you want is only when you input 12 to your program. However, this is only for the upper triangle.

I think if you want an exact value as you intended, you should not let the user input a value. Instead, try finding the formula and print it using the loops.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1