Pr.Pg Next Pg

C Program tutorials to Convert Amount to Word

C Program to Convert Amount to Word

Sam Sir

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

void main()

{

int no,no_hund,no_ten,no_unit,last_two_digit;

char hund[30];

char tens[30];

char unit[30];

 

printf("Enter any 3 Digit no : ");

scanf("%d",&no);

if (no>999)

{printf("%d is above 3 digit no",no);

goto last;

}

 

no_hund=no/100;

no_unit=no%10;

no_ten=(no%100-no_unit)/10;

 

printf("\n %d %d %d \n",no_hund,no_ten,no_unit);

 

switch(no_hund)

{ case 1:

strcpy(hund,"One Hundred "); break;

case 2:

strcpy(hund,"Two Hundred "); break;

case 3:

strcpy(hund,"Three Hundred ");break;

case 4:

strcpy(hund,"Four Hundred "); break;

case 5:

strcpy(hund,"Five Hundred "); break;

case 6:

strcpy(hund,"Six Hundred "); break;

case 7:

strcpy(hund,"Seven Hundred "); break;

case 8:

strcpy(hund,"Eight Hundred "); break;

case 9:

strcpy(hund,"Nine Hundred "); break;

default:

strcpy(hund," ");

}

last_two_digit=no%100;

switch(last_two_digit)

{ case 11:

strcpy(tens,"Elevel"); break;

case 12:

strcpy(tens,"Twevle"); break;

case 13:

strcpy(tens,"Thirten "); break;

case 14:

strcpy(tens,"Fourteen "); break;

case 15:

strcpy(tens,"Fifteen "); break;

case 16:

strcpy(tens,"Sixteen "); break;

case 17:

strcpy(tens,"Seventeen"); break;

case 18:

strcpy(tens,"Eighteen"); break;

case 19:

strcpy(tens,"Nineteen"); break;

}

 

switch(no_ten)

{ case 2:

strcpy(tens,"Twenty "); break;

case 3:

strcpy(tens,"Thirty ");break;

case 4:

strcpy(tens,"Fourty "); break;

case 5:

strcpy(tens,"Fifty "); break;

case 6:

strcpy(tens,"Sixty "); break;

case 7:

strcpy(tens,"Seventy "); break;

case 8:

strcpy(tens,"Eighty "); break;

case 9:

strcpy(tens,"Ninety "); break;

default:

strcpy(tens," ");

}

 

switch(no_unit)

{ case 1:

strcpy(unit,"One"); break;

case 2:

strcpy(unit,"Two"); break;

case 3:

strcpy(unit,"Three");break;

case 4:

strcpy(unit,"Four"); break;

case 5:

strcpy(unit,"Five"); break;

case 6:

strcpy(unit,"Six"); break;

case 7:

strcpy(unit,"Seven"); break;

case 8:

strcpy(unit,"Eight"); break;

case 9:

strcpy(unit,"Nine"); break;

default:

strcpy(unit," ");

}

 

printf("\n \n Amount to Word = ");

printf("%s %s %s",hund,tens,unit);

last:

}

Output

Enter Any 3 Digit no : 159

1 5 9

 

Amount to Word = One Hundred Fifty Nine

 

Enter Any 3 Digit no : 750

7 5 0

 

Amount to Word = Seven Hundred Fifty

 

Enter Any 3 Digit no : 275

2 7 5

 

Amount to Word = Two Hundred Seventy Five

 

Pr.Pg border                                              Next Pg