Advertisements
Advertisements
प्रश्न
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)
कोड लेखन
Advertisements
उत्तर १
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
उत्तर २
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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
