char str[27] = "abcdefghijklmnopqrstuvwxyz"; |
この配列を使用して,以下のように反復表示するプログラムを if 文を使用しないで作成しましょう.
My student number: s134099 a c e g i k m o q s u w y b d f h j l n p r t v x c e g i k m o q s u w d f h j l n p r t v e g i k m o q s u f h j l n p r t g i k m o q s h j l n p r i k m o q j l n p k m o l n m ------------------------------- |
添字の変化をよく観察して,そのような数列をどうやって作るかを考えてください.
#include <stdio.h> main() { srand((unsigned) time(NULL)); char str[27] = "abcdefghijklmnopqrstuvwxyz"; int i, j, total = 25, stop = total; printf("My student number: s134099\n\n"); for(i=0; stop>=1; i++){ for(j=0; j<i; j++) printf(" "); for(j=i; j<=total; j+=2) printf("%c ", str[j]); total--; stop -= 2; printf("\n"); } printf("\n-------------------------------\n\n"); return(0); } |