1
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 3 years have passed since last update.

10進数の桁数確認プログラム

Posted at

unsigned long型で10^20までの桁数を確認するプログラムです。
素数判定プログラムで巨大数を扱ったときに0を数えるのがめんどくさいので作りました。
最速の素数判定プログラム C# Java C++
実用性重視でリファクタリング無しの駄作です。

WhatDecimal.c
/*
 ============================================================================
 Name        : WhatDecimal.c
 Author      : mio
 Version     : 1.0
 Copyright   : mio
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

# include <stdio.h>
# include <stdlib.h>
# include <math.h>

# define UNSIGNEDLONG_MAX 10000000000000000000
//18,446,744,073,709,551,615

int main() {
	while (1) {
		unsigned long input;
		unsigned long data;
		int cnt;

		scanf("%lu", &input);
		printf("data=%lu\n", input);

		for (cnt = 0, data = input; data > 0; data /= 10)
			cnt++;

		cnt--;
		printf("cnt zero=%d\n", cnt);

		printf("1");

		int flag = 1;
		for(;cnt>0;cnt--) {
			switch (cnt) {
			case 4 + 3 * 0:
				printf("man\n");
				cnt = 0;
				break;
			case 4 + 4 * 1:
				printf("oku\n");
				cnt = 0;
				break;
			case 4 + 4 * 2:
				printf("tyo\n");
				cnt = 0;
				break;
			case 4 + 4 * 3:
				printf("kei\n");
				cnt = 0;
				break;
			case 3 + 4 * 4:
				printf("gai\n");
				cnt = 0;
				break;
			case 3 + 4 * 5:
				printf("sen\n");
				cnt = 0;
				break;
			default:
				printf("0");
				break;
			}
		}
	}

	return 0;
}

1
0
1

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
1
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?