Skip to main content

ProwessApps

Learn · Practice · Excel

C Program to print the following series. 3 6 9 12 15 ... n terms

C Code Example — Series Programs

ADVERTISEMENT

C Program to print the following series. 3 6 9 12 15 ... n terms

Objective

Write a C program to print the series of multiples of 3: 3 6 9 12 15 ..... n terms.

Algorithm / Approach

  1. Read an integer n representing the total number of terms.
  2. Run a loop i from 1 to n.
  3. Inside the loop, calculate the term: value = i * 3.
  4. Print the value.
main.c
#include<stdio.h>
int main( ){
int n, i, value;
printf("Enter Value for N : ");
scanf("%d", &n);
for(i=1; i<=n; i++) {
value = i*3;
printf("%d ", value);
}
printf("\n");
return 0;
}

Expected Output

Enter Value for N: 10
3 6 9 12 15 18 21 24 27 30

Explanation of the Program

  • Notice that n here represents the number of *terms*, not the maximum limit. If the user enters 10, the loop runs 10 times and generates 10 multiples.
  • By multiplying the current loop iteration (1, 2, 3) by 3, we easily generate the multiples (3, 6, 9).

Complexity

Time Complexity O(n)
Space Complexity O(1)
ADVERTISEMENT