What is the program to print table of given number?
Hi Friends,
Please help me to sort out my problem regarding program code. I have to write the program which will display the table of the given number. I have tried this but my program code is giving unexpected output.
For example while the execution of the program if I pass five then it should print the table of five.
Your help will be appreciable..
Re: What is the program to print table of given number?
Hi,
I recommend you to use "While" loop in your program to print table of given number. Because "While" loop is much easier than "for" loop. For your convenience see the below program code:
Program:
Quote:
void main()
{
int p,a,k,x;
cout<<"provide the number to generate its table";
cin>>x;
cout<<"provide the number (table)";
cin>>m;
k=1;
while(k<=a)
{
p=x*k;
cout<<<"*"<<<"="<
k++;
}
getch();
}
Re: What is the program to print table of given number?
Dear friend,
Have you tried below logic to print table of given number?
Following program code is running successfully on my machine. I hope it will also works for you also.
Please try to run the below code:
Quote:
]
# include <conio.h>
void main()
{
clrscr ();
int p;
count << “ enter the number of which you want to print the table: “ ;
cin >> p;
count << p << “ * 1 = “ << p* 1 <
count << p << “ * 2 = “ << p* 2 <
count << p<< “ * 3 = “ << p* 3 <
count << p<< “ * 4 = “ << p* 4 <
count << p<< “ * 5 = “ << p* 5 <
count << p<< “ * 6 = “ << p* 6 <
count << p<< “ * 7 = “ << p* 7 <
count << p<< “ * 8 = “ << p* 8 <
count << p<< “ * 9 = “ << p* 9 <
count << p<< “ * 10 = “<< p*10 <
getch();
}
Re: What is the program to print table of given number?
Hi friend,
To solution for your problem is very easy. I have C program which displays the table of given number.
In this program first I accepted the number , then I used "For" loop to check condition, then I applied formula to calculate the table.
program:
Quote:
#include<conio.h>
#include<stdio.h>
void main()
{
int a,num1;
printf("Enter number");
scanf("%d",&num1);
for(a=1;a<=num1;a++)
printf("%d*%d=%d",num1,a,num1*a);
getch();
}
Re: What is the program to print table of given number?
Please use below logic in your program of printing table of given number:
Quote:
for(int l=1;l<=10;l++)
{
d=number*l
}
I hope it will solve your porplem..
Re: What is the program to print table of given number?
void main()
{
int a,b,i=0;
printf("Enter the number: ");
scanf("%d",&a);
while(i<11)
{
b=a*i;
printf("\n%d",b);
i++;
}
getch();
}