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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/c-programming-exercises/basic-declarations-and-expressions/c-programming-basic-exercises-79.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics