Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

โปรแกรม C แสดงตัวอักษรภาษาอังกฤษแบบเกลียว (Spiral Pattern)

รูปแบบเกลียวสำหรับตัวอักษร:

โปรแกรม C แสดงตัวอักษรภาษาอังกฤษแบบเกลียว (Spiral Pattern)

ตรรกะการแสดงตัวอักษรแบบเกลียว:

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("\n");    } } else{    printf("Please Enter from 1 to 13 only\n"); }

โปรแกรม

โปรแกรม C แสดงตัวอักษรแบบเกลียว:

#include<stdio.h> main(){    int i,rows,k=1;    printf("Enter number of Rows for Spiral Alpha Pattern from 1 to 13\n");    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("\n");       }    }else{       printf("Please Enter from 1 to 13 only\n");    } }

ผลลัพธ์

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