首页  >  文章  >  后端开发  >  C程序以螺旋模式表示字母

C程序以螺旋模式表示字母

WBOY
WBOY转载
2023-08-25 19:25:05762浏览

表示字母的螺旋图案如下 -

C程序以螺旋模式表示字母

螺旋模型中用于表示字母的逻辑如下 -

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>");
}

程序

以下是用 C 语言程序来表示螺旋图案中的字母 -

 现场演示

#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>");
   }
}

输出

当执行上述程序时,会产生以下结果 -

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

以上是C程序以螺旋模式表示字母的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除