Advertisements
Advertisements
Question
Write a program in C++ to accept a positive integer and display its multiplication table.
(Hint: if n = 5, then 5, 10, 15, 20, ......., 50)
Code Writing
Advertisements
Solution 1
Without using a class:
#include<iostream h>
#include<conio.h>
void main()
{
int n, i;
cout<<"Enter a number of which table is to be created";
cin>>n;
for(i=1; i<=10; i++)
{
cout<<n*i<<endl;
}
getch();
}shaalaa.com
Solution 2
Using a class:
#include<iostream.h>
#include<conio.h>
class table
{
int n, i;
public;
void display()
{
cout<<"Enter a number of which table is to be created";
cin>>n;
for(i=1;i<=10;i++)
{
cout<<n*i<<endl;
}
}
};
void main()
{
table t;
t.display();
}shaalaa.com
Is there an error in this question or solution?
