0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C言語 アスタリスク表示

Posted at

この記事について

・Forループによるアスタリスク表示

今日のソース

入力した整数分だけ "*" を表示する。ただし、3個表示ごとにスペースを表示する。
負の数が入力された場合は、再入力のメッセージを表示する。

#include <stdio.h>

int n;
int a = 3;

int main(void)
{
	printf("入力した数字:");
	scanf("%d",&n);
	
	if(n >= 0){
		for(int i=0; i<n; i++){
		
			printf("*");
			
			if((i+1)%a == 0){
			
				printf(" ");
			}
		}
	
	}else{
			printf("0以上を入力して下さい。\n");
	}
	return 0;

実行結果

入力した数字:24
 *** *** *** *** *** *** *** *** 

やってみて思ったこと

昔、何かの課題で2重ループによるピラミッドやひし形を表示させたな。
そのうち、円を表示させてみるか。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?