C Exercises: Produce the following table of values
C Basic Declarations and Expressions: Exercise-79 with Solution
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 Code Editor:
Previous:Write a C program to demonstrates the difference between predecrementing and postdecrementing using the decrement operator --.
Next: Write a C program that reads the side (side sizes between 1 and 10 ) of a square and prints square using hash (#) character.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join