w3resource

C Exercises: Produce the following table of values


Generate a table with x,x+2,x+4 using loops

Write a C program using looping to produce the following table of values.

x       x+2     x+4     x+6
--------------------------------
1       3       5       7
4       6       8       10
7       9       11      13
10      12      14      16
13      15      17      19

Sample Solution:

C Code:

#include<stdio.h>
int main()
{
    int x; // Declare variable x
    
    // Print header for table
    printf("x\tx+2\tx+4\tx+6\n\n");
    printf("---------------------------\n");
    
    // Loop to generate and print table values
    for(x=1; x<=15; x+=3)
        printf("%d\t%d\t%d\t%d\n", x, (x+2), (x+4), (x+6));    
    
    return 0; // Indicate successful program execution
}

Sample Output:

x	x+2	x+4	x+6

---------------------------
1	3	5	7
4	6	8	10
7	9	11	13
10	12	14	16
13	15	17	19

Flowchart:

C Programming Flowchart: Produce the following table of values.


For more Practice: Solve these Related Problems:

  • Write a C program to generate a table of sequences where each row is defined by a starting number and an arithmetic progression with a step of 2.
  • Write a C program to print a table of values for x, x+2, x+4, and x+6 using nested loops with dynamic input.
  • Write a C program to generate and display a table of consecutive arithmetic sequences with a common difference of 2.
  • Write a C program to produce a table with multiple columns where each column increments by a fixed value starting from a user-defined base.

Go to:


PREV :Demonstrate predecrementing vs postdecrementing.
NEXT : Print a filled square of size nnn using #.

C programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.