Closed. This question is off-topic . It is not currently accepting answers.
#include <iostream>
using namespace std;
int main(){
const auto n = 4;
auto count = 0;
for (auto i = 2; i <= n * 2; i += 2)
{
for (auto j = i; j > 0; j -= 2)
std::cout << j << " ";
std::cout << std::endl;
for (auto j = 0; j < (i == 2 ? i : i + 2); j += 3)
std::cout << count * 3 << " ";
++count;
std::cout << std::endl;
}
return 0;
}
Edit: Corrected...
A little near to the answer
2
0 ==> true
4 2
0 3 ==> should be 3 3
6 4 2
0 3 6 ==> should be 6 6 6
8 6 4 2
0 3 6 ==> should be 9 9 9
What does the '\n' character do?, that the corresponding argument is to be treated as a string (in C terms, a 0-terminated sequence of char ); the type of the corresponding argument must be char * . I need to print this table 2 0 4 2 3 3 6 4 2 6 6 6 8 6 4 2 9 9 9 9 I have written this code for the following result #include <iostream> using namespace std; int main(){ const int
Here is another approach for case when you're providing number of repeats (like in @Ruks answer):
void printSequence(unsigned int repeats)
{
int n = 2;
for(int i = 1; i < repeats; i++)
{
n+=2*i;
}
//n - number of all numbers in sequence for given number of repeats
int step = 0;
int numsPerRow = 1;
for(int i = 0; i < n; i+=step)
{
for(int j = numsPerRow; j > 0; j--)
{
std::cout << 2*j << " ";
}
std::cout << std::endl;
for(int j = 0; j < numsPerRow; j++)
{
std::cout << step+numsPerRow-1 << " ";
}
std::cout << std::endl;
step+=2;
numsPerRow++;
}
}
How to print printf("Hello world."); using printf() in c programming , using printf, but in scanf in format specifier we place “Scansets”([^\n]). [^\n] by keeping these,scanf read until reach new line in command line. Print Table of Any Number Program in C. The concept of generating table of any number is, particular number is multiply from 1 to 10. The concept of generate Table of any number is : number * 1 number * 2 number * 3 number * 4 number * 5 number * 6 number * 7 number * 8 number * 9 number * 10. Find table of any number
Use this:
void print_sequence(unsigned long long const repeat = 4, unsigned long long const i = 0)
{
for (auto j = (i + 1ull) * 2ull; j > 2ull; j -= 2ull)
std::cout << j << " ";
std::cout << (repeat > 0ull && repeat < -1ull ? "2\n" : "");
for (auto j = 0ull; j < i; j++)
std::cout << i * 3ull << " ";
std::cout << (repeat > 0ull && repeat < -1ull ? std::to_string(i * 3ull) + "\n" : "");
if (repeat < -1ull && i + 1ull < repeat)
print_sequence(repeat, i + 1ull);
}
Edit: The shortest and strongest method I can think of...
And call it like this:
print_sequence();
If you don't want 4 times:
print_sequence(10)
It will repeat it as many times you want...
Kind regards,
Ruks.
How to get and print a string with spaces without gets, puts or string , The code to print the inventory should use the length specifier in printf format like this: gotoxy(0, 10); while (fscanf(fp, "%d %s %d %f", &a.id, a.name, &a.quantity, This program will print table of numbers from 1 to 20 using nested looping. There are two loops using parent loop to run from 1 to 20 and child loop to run from 1 to 10 to print table of corresponding number which is coming from parent loop. Print table from 1 to 20 using C program. /*C program to print table of numbers from 1 to 20*/ #include
7. print or read the flyer. throughout the chapter, you will see an abbreviated form of this roadmap. formatting flyer after formatting (b) Formatted Flyer Figure 1–13 the projects, but Identify the tables that will be included in the database. 2. Write C++ program to print multiplication table of a given number. HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, //Printing table of number entered by user.
Through the rotation of the crank-pins c and d, the forms are at first fully drawn combination of levers, all the color-plates h are placed between the forms a' a” The printing-tables, which are also covered with an elastic material, serve as a In this video i have explain about how to create a program of printing a table of any number in c# with the help of visual studio developer command prompt console window.
printf is the C language function to do format- ted printing. The same \f form feed. \n newline (linefeed) This was very useful in printing tables because small and large combined the options plus, minus, and five, or space, minus, and five In this example, you will learn to generate the multiplication table of a number entered by the user. To understand this example, you should have the knowledge of the following C programming topics: The program below takes an integer input from the user and generates the multiplication tables up to 10. Here's a little modification of the above
Comments 1) change your logic to create the numbers such that for both you have the outer loop index correspond to the line number 2) combine both into one I asked how do I combine them and your answer is , combine them ! Wow read the comment again more carefully.... I suggest to create sub-functions: one to create multiple of 3, on for decreasing even numbers. then write both loop to have i = 0 -> 4. then merge loop. #include <iostream> using namespace std; int main(){ const int N = 9; for(int i = 2; i <= N; i += 2){ for (int j = i; j > 0; j -= 2) { cout << j << " "; } cout << endl; for(int j = 0; j <= i; j +=3) { cout << j << " "; } cout << endl; } return 0; }
You should add this to the question instead of putting it here. Does it work now? Is it 9 9 9
or 9 9 9 9
because your question looks different... And it is working for me... Then use (i == 2 ? i : i + 2)
instead of just i
in the second for loop condition. I edited that in your answer too. Okay, now your code is working properly... I am not at that level of C++ . We are just going throught for loops . And this problems needs to be solved with simple for loops . @TrevorPhilip Which part of it is "that level of C++" ? If you want, you can remove the if statements inside the for-loop, that won't make a big difference (would add extra spaces at the end of each line)... You can see my answer . That's my level of understanding C++ I don't think of it more than simple arithmetic and for-loops always look the same in syntax, nothing new there. Just try reading it carefully and tell me where you stop. So can you help my correcting my answer rather than understanding yours ? Because I lack of time , and I am near to the answer .