In this post, we will talk about how we print the table, we will use the traps to print the table, and we will show it again by explaining how we print the table. Read this post today, 3 great ways to print a table in c language, then you will know how the system works. To print a table you need to know about loops, because we will use traps to print a table. Although printing a table is not a difficult task, many people find it difficult to understand.
best 3 ways to print table in c language
As you know we will use loops to print the table. And you will also know that there are mainly two types of loops. 1.) Entry control loop 2. ) Exit control loop1) Control loop (Entry)
for loop: - If you learn any programming language, the most widely used loop, and with the help of this we can create many types of programs. The most important thing about this loop is that if the situation is false, then this loop does not work at all. And this is also called the entry control loop.
Syntax = for(value initilization ; condition ; increement/decreement)
{
statement 1 ;
statement 2 ;
statement 3 ;
statement n;
}
while loop :- This
loop is also very popular, a lot of people use this loop as well,
according to the problem , we use loops. We also call it the entry
control loop.
Syntax= while(condition)
{
statement 1 ;
statement 2 ;
statement 3 ;
statement n ;
}
2) Control loop (Exit)
do while loop :- Very few people use this loop, if the given condition is false, then the loop executes at least once. This is also called exit control loop. Syntax= do
{
statement 1 ;
statement 2 ;
statement 3 ;
}
while(condition);
print table by use of loop
If you have seen the syntax of for loop, then you have to take care of three things, which we will discuss in turn.Value initilization: -
This is the part from where we initilize the value to start the loop,
we know that the table always starts with a multiple of one (1 * 1), and then its value increases.
for example :- (2*1),(2*2),(2*3) etc .
To
print the table we have to initilize the value 1, and for that we have
to declare a variable, for example we have to declare the variable (i).
i = 1;
Condition: - This is
the part where we tell when to end the loop, the control of the loop
comes out as soon as our given condition becomes false. And you know
that the table is only up to a multiple of 10, so we give a specific
condition to print the table.
i <=10;
As soon as the value of i is equal to 10, the loop control will come
out.
Increement/Decreement: - Now to change the value of i, we have to
use this part, now you think that to print the table, the value of i is
increase or decrease. Obviously, to print the table, we have to
increase the value of i, else you will understand yourself further.
i++ ;
statement: - Now our loop will start doing its work, but now we will tell you what to do with the loop by our statement.
For example, if we want to print a table of 8, then statement are executed that this is the program, which we will cover step by step now.
When you see the statement inside the loop, you must be wondering how the table will be printed. So let's see.
When you see the statement inside the loop, you must be wondering how the table will be printed. So let's see.
Explain:
We have declared three variable names named i, T, n, where T is the
output of our table. Now i = 1, so when you look at the statement and
apply the value in it, then you will know what is happening.
T = 8 * 1 Here we have written both the value of n and the value of i,
so you will know what T will print. answer is = 8
Now the condition of the loop will be checked, which is still true
because we have condition (i <= 10), meaning the value of i is
currently smaller than 10, now the value of i will increase by one (i
++).
Now with the increase in value of i T = 8 * 2 , T will now print 16 and
due to the presence of \ n, 16 will print from the new line.
Now the condition will be checked again, and when it is incremented, now
the value of i will be 3, and T will print 24 in the new line, and so
the loop will continue, and the value of i will increase, as long as the
condition follows. It does not happen. when the condition is false ,
then the loop come out from the curly bracess.
So in this way we can print the table with the help of for loop and the
same process applies to each loop.
It works exactly like a for loop, just in this we have already initialized i = 1, in this way we can also print the table using a while loop.
print table using while loop
It works exactly like a for loop, just in this we have already initialized i = 1, in this way we can also print the table using a while loop.
print table with use of while loop
You will know that the do while loop condition is executed at least once even if it is false, then we will print the table something like this with the help of do while.If you look closely, we place the semicolon behind the temporary loop, so that the process is repeated. Here the value is printed first, followed by the value of i, and then after the condition is checked, if the condition is true then the loop will repeat, and will continue until the condition is false.
We hope you like our post the best way to print a table in C language. If you have questions, you can comment. If you think this post might help someone else, don't forget to share it. You must subscribe to our blog, as soon as we upload new posts, notification is available. Don't forget to read.
Tags :-
c compiler,
online c compiler,
c language,
objective c,
c programming language,
the c programming language,
c tutorial
0 Comments