首頁  >  文章  >  後端開發  >  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刪除