c語言小寫金額轉換大寫金額
⑴ c語言小寫轉大寫怎麼編
#include <含信stdio.h> void main() { char a,b; printf("請輸入一個小寫字母"); scanf("%c"中局,&a); b=a-32; printf("%c",b); } 小寫轉大寫是要-的賣老讓,a的鍵控代碼97,A是65 最簡單易懂又不易錯的方法:b=a-'a'+'A'
⑵ C語言編程:用指針編程序實現,輸入一個人民幣小寫金額值,轉化為大寫金額值輸出。
#include "stdafx.h"
#include<stdio.h>
#define NUM1 1
#define NUM2 2
#define NUM3 3
#define NUM4 4
#define NUM5 5
#define NUM6 6
#define NUM7 7
#define NUM8 8
#define NUM9 9
#define NUM 10
#define NUM10 11
#define NUM100 12
#define NUM1000 13
#define NUM10000 14
#define NUM100000 15
#define NUM1000000 16
#define NUM10000000 17
#define NUM100000000 18
#define NUM1000000000 19
#define NUM10000000000 20
void show_num(int *save,int count)
{
int i=count;
while(i>=0)
{
switch(save[i])
{
case 1:
printf("一");
break;
case 2:
printf("睜鏈燃二");
break;
case 3:
printf("三");
break;
case 4:
printf("四");
break;
case 5:
printf("五");
break;
case 6:
printf("六");
break;
case 7:
printf("七");
break;
case 8:
printf("八");
break;
case 9:
printf("九");
break;
case NUM10:
printf("十");
break;
case NUM100:
printf("百");
break;
case NUM1000:
printf("千");
break;
case NUM10000:
printf("萬");
break;
case NUM100000:
printf("十");
break;
case NUM1000000:
printf("百");
break;
case NUM10000000:
printf("千"悉虛);
break;
case NUM100000000:
printf("億");
break;
default:
break;
}
i--;
}
printf("\n");
}
int main()
{
long int num=0,i=0;
int save[20]={0};
printf("請輸入要大喚哪寫的數值:");
scanf("%d",&num);
while(num)
{
save[i]=num%10;
num=num/10;
save[i+1]=NUM10+i/2;
i+=2;
}
show_num(save,i-2);
return 0;
}
如果有需要,自己太添加,就在那個switch裡面,還有宏,
但是不能超過你定義的類型的最大值,否則會出錯哦
漢字部分自己改把
⑶ C語言 小寫數字轉換大寫漢字
應該是小寫字母轉大寫字母。
#include<stdio.h>
char*toUpper(char*src)
{
inti=-1;
while(src[++i])
if(src[i]>='a'&&src[i]<='z')//如果是小寫字元冊橡耐,減去32就是大小寫了
如行src[i]-=32;
returnsrc;
}
intmain()
{
州春charp[]="acsavh4516;';gbasff";
printf("relust=%s ",toUpper(p));
return0;
}
⑷ c++將小寫金額轉化為大寫金額,以及日期格式轉化
#pragma
warning(disable:4786)
#include
<string>
#include
<stdio.h>
#include
<iostream>
#include
<vector>
using
std::vector;
using
std::string;
using
std::cout;
using
std::cin;
using
std::endl;
string
ConvertMoney(double
dNum)
{
string
strResult;//要返回的字元串
char
c_Digit[20];//c風格的字元數組
string
strDigit;//輸入的數字字元串
int
iLength
=
0;//輸入的雙精度數的長度
int
iAddZero
=
0;//加零標志
int
iDigit
=
0;//取出的數字
string
str1[]
=
{"分","角","元","拾","佰","仟","萬",
"拾","佰","仟","億","拾","佰","仟","萬","拾","佰","仟"};
string
str2[]
=
{"零","壹","貳","叄","肆","伍","陸","柒","捌","玖"};
vector<string>
strUnit(str1,str1
+
18);//初始化向量
vector<string>
strUpperNum(str2,str2
+
10);
sprintf(c_Digit,"%.0f",dNum*100);//將數字串換成c風格的數組
strDigit
=
c_Digit;//將字元數組的內容賦值給string變數
iLength
=
strDigit.length();//取得字元串的長度
if
(iLength
>
15
||
iLength
<
0)//如果輸入的數字超殲清出double類型數據的長度的話返回「error「
return
"Error";
for
(int
i
=
0;
i
<
iLength;
i++)
{//將字元串逐位處理
iDigit
=
atoi(strDigit.substr(i,1).c_str());
if
(iDigit
==
0)//如果當前位為零,則將加零標志+1
iAddZero++;
else
{
if
(iAddZero
>
0)//如果當前為不為0,且加0標志大於0
strResult
+=
"零";//則在字元串中加入「零「
strResult
+=
strUpperNum[iDigit];
iAddZero
=
0;
}
//該位不為0||元位||億位||萬位
if
((iDigit
!=
0)
||
(iLength
-
i
==
3)
||
(iLength
-
i
==
11)||((iLength
-
i
+
1)%8
==
0
&&
(iAddZero
<
4)))
strResult
+=
strUnit[iLength
-
i
-
1];
}
if
(strDigit.substr(strDigit.length()
-
2,2)
==
"00")
strResult
+=
"整";
return
strResult;
}
int
main()
{
double
dLowerRMB
=
0.0;
cout
<<
"請穗碰輸入要轉換的人民幣金額!"
<<
endl;
cin
>>
dLowerRMB;
cout
<<
"-------------------------------------------------"
<<
endl;
cout
<<
"您要轉換的人民幣小寫金額為
"
<<
"\n"
<<
dLowerRMB
<<
endl;
cout
<<
"-------------------------------------------------"
<<
endl;
string
strUpperRMB
=
ConvertMoney(dLowerRMB);
cout
<<
"大寫金額為猜改談"
<<
"\n"
<<
strUpperRMB
<<
endl;
cout
<<
"-------------------------------------------------"
<<
endl;
return
0;
}
⑸ C語言編程:數字金額轉換為中文大寫金額
#include<stdio.h>
#include<conio.h>
main()
{
int i,size=0;
char s[11];
printf("請輸入金額:");
scanf("%s",s);
printf("次數的中文大寫金額為:\n\n");
printf("佰\t拾\t萬\t仟\t佰\t拾消孝\t元\t角\t分\n");
for(i=0;s[i]!='\0';i++)
{
if(s[i]=='.') break;
size++;
}
for(i=0;i<(7-size);i++)
{
printf(" \t");
}
for(i=0;s[i]!='\0';i++)
{
switch(s[i])
{
case '0':printf("零\t");break;
case '1':printf("壹\t"拿蔽稿);break;
case '2':printf("貳\t");break;
case '3':printf("叄\並扒t");break;
case '4':printf("肆\t");break;
case '5':printf("伍\t");break;
case '6':printf("陸\t");break;
case '7':printf("柒\t");break;
case '8':printf("捌\t");break;
case '9':printf("玖\t");break;
}
}
getch();
}
結果:(可能不是你想要的,如果不是你想要的結果,你能給我你想要的結果嗎?)
⑹ c語言編寫一個能夠將人民幣小寫金額自動轉化為大寫寫金額的程序寫出程序語句
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
string ConvertMoneyCaps(long double moneySum)
{
long int temp_i = (long int)moneySum; /**//* 整數部分 */
float temp_f = moneySum - temp_i; /**//* 小數部分 */
int digit = 0, i, j, k, num_i;
string money("");
char num[20], *p;
char name[][3] = {"元","拾","佰","仟","萬","億"};
char numchar[][3] = {"零","壹","貳","叄","肆","伍","陸","柒","捌","玖"};
ltoa(temp_i, num, 10); /**//* 整數部分轉換成字元串後在搏畢慎處理 */
p = num;
digit = strlen(num); /**//* 整數部分位數 */
/**//*--------處理整數部分 start--------*/
for(i = 1; i <= digit; i ++)
{
k = (digit - i) % 4;
if(isdigit(*p))
{
num_i = *p & 0xF; /**//* 把字元轉換成數字,比如 '0'-> 0,'1' ->基敬 1*/
/**//*--------轉換數字開始---------*/
if(num_i)
{
money = money+ numchar[num_i];
}
else
{
if(k && (*(p + 1) &0xF))
money += "零";
}
/**//*--------轉換數字結束-------*/
/**//*---------添加計數單位開始----*/
if(k)
{
if(num_i)
money = money + name[k];
}
else
{
j = digit - i;
if(j)
money = money + name[j/4 + 3];
else
money += "元";
}
/**//*--------添加計數單位結束數並--------*/
p++;
}
else
{
money = "遇到非數字退出!";
return money;
}
}
/**//*--------處理整數部分 End --------*/
/**//*--------處理小數部分 start--------*/
if(temp_f > 0.01)
{
if((int)(temp_f*10)) money = money + numchar[(int)(temp_f*10)] + "角";
if((int)(temp_f*100)%10) money = money + numchar[(int)(temp_f*100)%10] + "分";
}
/**//*--------處理小數部分 End--------*/
money += "整";
return money;
}
int main()
{
long double x = 33.20;
cout << "please input the money:";
cin >> x;
cout << "Convert Money Caps:";
string money = ConvertMoneyCaps(x);
cout << money <<endl;
return 0;
}