Home > Backend Development > C++ > body text

C program to represent letters in spiral pattern

WBOY
Release: 2023-08-25 19:25:05
forward
770 people have browsed it

The spiral pattern representing letters is as follows-

C program to represent letters in spiral pattern

##The logic used to represent letters in the spiral model is as follows-

if(rows<=13 && rows>=1){
   for(i=1;i<=rows*2;i+=2){
      if(k%2==1){
         printf("%c %c",i+64,i+65);
         k++;
      }else{
         printf("%c %c",i+65,i+64);
         k++;
      }
      printf("</p><p>");
   }
}
else{
   printf("Please Enter from 1 to 13 only</p><p>");
}
Copy after login

Program

The following is a C language program to represent the letters in the spiral pattern-

Live demonstration

#include<stdio.h>
main(){
   int i,rows,k=1;
   printf("Enter number of Rows for Spiral Alpha Pattern from 1 to 13</p><p>");
   scanf("%d",&rows);
   if(rows<=13 && rows>=1){
      for(i=1;i<=rows*2;i+=2){
         if(k%2==1){
            printf("%c %c",i+64,i+65);
            k++;
         }else{
            printf("%c %c",i+65,i+64);
            k++;
         }
         printf("</p><p>");
      }
   }else{
      printf("Please Enter from 1 to 13 only</p><p>");
   }
}
Copy after login

Output

When the above program is executed, the following results will be produced-

Enter number of Rows for Spiral Alpha Pattern from 1 to 13
10
A B
D C
E F
H G
I J
L K
M N
P O
Q R
T S
Copy after login

The above is the detailed content of C program to represent letters in spiral pattern. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!