金種表


  パターン1 : 整数変数の演算結果の小数以下が切り捨てられるのを利用する




#include "stdio.h"

void main()
{
	// 変数定義
	long Kin;
	long Man,Sen_5,Sen_2,Sen_1,Hyak_5,Hyak_1,Jyu_5,Jyu_1,Go,Ichi;

	// 初期化
	Man = 0;
	Sen_5 = 0;
	Sen_2 = 0;
	Sen_1 = 0;
	Hyak_5 = 0;
	Hyak_1 = 0;
	Jyu_5 = 0;
	Jyu_1 = 0;
	Go = 0;
	Ichi = 0;

	// 入力
	scanf( "%ld", &Kin );

	// 一万円
	Man = Kin / 10000;
	Kin = Kin - Man * 10000;
	
	// 5千円
	Sen_5 = Kin / 5000;
	Kin = Kin - Sen_5 * 5000;
	
	// 2千円
	Sen_2 = Kin / 2000;
	Kin = Kin - Sen_2 * 2000;
	
	// 千円
	Sen_1 = Kin / 1000;
	Kin = Kin - Sen_1 * 1000;
	
	// 5百円
	Hyak_5 = Kin / 500;
	Kin = Kin - Hyak_5 * 500;

	// 百円
	Hyak_1 = Kin / 100;
	Kin = Kin - Hyak_1 * 100;

	// 50円
	Jyu_5 = Kin / 50;
	Kin = Kin - Jyu_5 * 50;

	// 10円
	Jyu_1 = Kin / 10;
	Kin = Kin - Jyu_1 * 10;

	// 5円
	Go = Kin / 5;
	Kin = Kin - Go * 5;

	// 1円
	Ichi =  Kin;

	// 表示
	printf( "一万円は %ld 枚\n", Man );
	printf( "5千円は %ld 枚\n", Sen_5 );
	printf( "2千円は %ld 枚\n", Sen_2 );
	printf( "1千円は %ld 枚\n", Sen_1 );
	printf( "500円は %ld 枚\n", Hyak_5 );
	printf( "100円は %ld 枚\n", Hyak_1 );
	printf( "50円は %ld 枚\n", Jyu_5 );
	printf( "10円は %ld 枚\n", Jyu_1 );
	printf( "5円は %ld 枚\n", Go );
	printf( "1円は %ld 枚\n", Ichi );

}

  パターン2 : C で利用できる演算の書き方を使う




<div id="sh_527ba0412d332">
<style type="text/css"> 
.syntaxhighlighter { 
	word-wrap:break-word!important; 
} 
 
#sh_527ba0412d332 .syntaxhighlighter div,#sh_527ba0412d332 .syntaxhighlighter span,#sh_527ba0412d332 .syntaxhighlighter code { 
	font-size:12px!important; 
	font-family: "メイリオ","MS Pゴシック"!important; 
} 
</style> 
 
<div style='width:600px;'> 
<pre name="code131107231425" class="brush:cpp">
#include "stdio.h"

void main()
{
	// 変数定義
	long Kin;
	long Man,Sen_5,Sen_2,Sen_1,Hyak_5,Hyak_1,Jyu_5,Jyu_1,Go,Ichi;

	// 初期化
	Man = 0;
	Sen_5 = 0;
	Sen_2 = 0;
	Sen_1 = 0;
	Hyak_5 = 0;
	Hyak_1 = 0;
	Jyu_5 = 0;
	Jyu_1 = 0;
	Go = 0;
	Ichi = 0;

	// 入力
	scanf( "%ld", &amp;Kin );

	// 一万円
	Man = Kin / 10000;
	Kin = Kin - Man * 10000;
	
	// 5千円
	Sen_5 = Kin / 5000;
	Kin = Kin - Sen_5 * 5000;
	
	// 2千円
	Sen_2 = Kin / 2000;
	Kin = Kin - Sen_2 * 2000;
	
	// 千円
	Sen_1 = Kin / 1000;
	Kin = Kin - Sen_1 * 1000;
	
	// 5百円
	Hyak_5 = Kin / 500;
	Kin = Kin - Hyak_5 * 500;

	// 百円
	Hyak_1 = Kin / 100;
	Kin = Kin - Hyak_1 * 100;

	// 50円
	Jyu_5 = Kin / 50;
	Kin = Kin - Jyu_5 * 50;

	// 10円
	Jyu_1 = Kin / 10;
	Kin = Kin - Jyu_1 * 10;

	// 5円
	Go = Kin / 5;
	Kin = Kin - Go * 5;

	// 1円
	Ichi =  Kin;

	// 表示
	printf( "一万円は %ld 枚\n", Man );
	printf( "5千円は %ld 枚\n", Sen_5 );
	printf( "2千円は %ld 枚\n", Sen_2 );
	printf( "1千円は %ld 枚\n", Sen_1 );
	printf( "500円は %ld 枚\n", Hyak_5 );
	printf( "100円は %ld 枚\n", Hyak_1 );
	printf( "50円は %ld 枚\n", Jyu_5 );
	printf( "10円は %ld 枚\n", Jyu_1 );
	printf( "5円は %ld 枚\n", Go );
	printf( "1円は %ld 枚\n", Ichi );

}
</pre>
</div>
</div>
<script type="text/javascript">
dp.SyntaxHighlighter.HighlightAll("code131107231425"); 
</script>


  パターン3 : 配列とループを利用する

#include "stdio.h"

void main()
{
	// 変数定義
	long Kin;
	long Kinsyu[10];
	long Tani[10];
	long Amari;
	long i;

	// 初期化
	for( i = 0; i < 10; i++ ) {
		Kinsyu[i] = 0;
	}
	Tani[0] = 10000;
	Tani[1] = 5000;
	Tani[2] = 2000;
	Tani[3] = 1000;
	Tani[4] = 500;
	Tani[5] = 100;
	Tani[6] = 50;
	Tani[7] = 10;
	Tani[8] = 5;
	Tani[9] = 1;

	// 入力
	scanf( "%ld", &Kin );

	for( i = 0; i < 9; i++ ) {
		Amari = Kin % Tani[i];
		Kinsyu[i] =  ( Kin - Amari ) / Tani[i];
		Kin = Amari;
	}

	// 1円
	Kinsyu[9] =  Kin;

	// 表示
	for( i = 0; i < 10; i++ ) {
		printf( "%ld 円は %ld 枚\n", Tani[i], Kinsyu[i] );
	}

}

  パターン4 : さらにステップアップした書き方

#include "stdio.h"
#include "memory.h"
#include "stdlib.h"

void main()
{
	// 変数定義
	long nKin;
	long nKinsyu[10+1];
	long nTani[] = { 0,10000,5000,2000,1000,500,100,50,10,5,1 };
	long i;

	// 初期化
	memset( (char *)nKinsyu, 0x00, sizeof( long ) * (10+1) );

	// 入力
	scanf( "%ld", &nKin );
	if ( nKin <= 0 ) {
		printf( "正しい数値を入力して下さい" );
		exit( 1 );
	}

	// 1円
	nKinsyu[10] =  nKin % 5;

	for( i = 1; i <= 10; i++ ) {
		nKinsyu[i] =  nKin / nTani[i];
		nKin = nKin % nTani[i];
	}

	// 表示
	for( i = 1; i <= 10; i++ ) {
		printf( "%ld 円は %ld 枚\n", nTani[i], nKinsyu[i] );
	}

}




yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[sc]
CCBot/2.0 (https://commoncrawl.org/faq/)
24/12/09 08:10:30
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube