
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C program to represent the numbers in spiral pattern
The spiral pattern to represent the numbers is shown below −
The logic applied to print the numbers in spiral pattern is as follows −
for(i=1;i<=rows*2;i+=2){ if(k%2==1){ printf("%3d %3d",i,i+1); k++; }else{ printf("%3d %3d",i+1,i); k++; } printf("
"); }
Program
Following is the C program for representing the numbers in spiral pattern −
#include<stdio.h> main(){ int i,rows,k=1; printf("Enter number of Rows for Spiral Pattern
"); scanf("%d",&rows); for(i=1;i<=rows*2;i+=2){ if(k%2==1){ printf("%3d %3d",i,i+1); k++; }else{ printf("%3d %3d",i+1,i); k++; } printf("
"); } }
Output
When the above program is executed, it produces the following result −
Enter number of Rows for Spiral Pattern 10 1 2 4 3 5 6 8 7 9 10 12 11 13 14 16 15 17 18 20 19
- Related Articles
- C program to represent the alphabets in spiral pattern
- Java Program to Print Spiral Pattern of Numbers
- Golang Program to Print Spiral Pattern of Numbers
- Swift program to print spiral pattern
- C Program to display the numbers in X pattern
- Program to print a pattern of numbers in C++
- C++ program to represent the Fraction of Two Numbers in the String Format
- Print numbers in matrix diagonal pattern in C Program.
- C program to represent numbers in numerator and denominator in string format
- C++ program to count minimum number of binary digit numbers needed to represent n
- Swift Program to Print Left Triangle Pattern of Numbers
- Spiral Matrix in C++
- Program to print Interesting pattern in C++
- Program to print Kite Pattern in C++
- Program to print number pattern in C

Advertisements