Skip to main content

C program to accept number and display it in words.


C program to accept number and display it in words.




#include <stdio.h>
#include <string.h>
#include <conio.h>

 
void main(){
    char init[27][12] = {" one "," two "," three ",
                " four "," five "," six ",
                " seven "," eight "," nine ",
                " ten "," eleven "," twelve ",
                " thirteen "," fourteen "," fifteen ",
                " sixteen "," seventeen "," eighteen ",
                " nineteen "," twenty "," thirty ",
                " fourty "," fifty "," sixty ",
                " seventy "," eight "," ninty "};
    char sthou[20]="",shund[20]="",sval1[20]="",sval2[20]="",result[100]="";
    int thou=0,hund=0,ten=0,temp=0,val1
,val2,num,rem,c=0;

clrscr();
        

     printf("******AMOUNT IN WORDS******  \n\n");
     printf("Enter any value (upto 4 digits) : ");
     scanf("%d",&num);
     while(num>0){
     rem = num%10;
     c++;
     if(c<=2)
    temp = temp * 10  +rem;
     else if(c==3)
    hund = rem;
     else if(c==4)
    thou = rem;
         num = num/10;
     }
     while(temp>0){  //as ten contains two digit so reverse it
        rem = temp%10;
        ten = ten * 10 + rem;
        temp= temp/10;
     }

     if(thou>0){
       strcpy(sthou,init[thou-1]);
       strcat(sthou," thousand ");
       strcat(result,sthou);
     }

     if(hund>0){
       strcpy(shund,init[hund-1]);
       strcat(shund," hundred ");
       strcat(result,shund);
     }

     if(ten>0){
          if(ten>20){
          val1 = ten/10;
          val2 = ten%10;
          }
          if(val1>0){
           strcpy(sval1,init[val1+(18-1)]);
           strcat(result,sval1);
          }
          if(val2>0){
           strcpy(sval2,init[val2-1]);
           strcat(result,sval2);
          }
     }
     printf("\n\nAmount in word is as under:\n \n");
     printf("_________________________________________________\n");
     printf("*|%s                 |*",result);
     printf("\n_______________________________________________\n");

getch();
}



Output:


Comments

Popular posts from this blog

C Program to print the pattern

C Program to print the pattern X X Y X Y Z ........................................................................................ #include<stdio.h> #include<conio.h> void main () { int i , j ; for ( i= 88 ; i< 91 ;i ++) { for ( j = 88 ;j <= i ; j ++) { printf ( "%c" , j );                    }           printf ( "\n" ); } getch (); } ........................................................................................ OUTPUT

Deen Dayal Upadhyay Gorakhpur University RESULTS

DDU Gorakhpur results chahiye to yaha click kare                                                                       RESULTS  

RESULT DDU Gorakhpur 2016

Deen Dayal Upadhyay Gorakhpur University   Check Your Result click Here  B. Sc. Part-II 26-MAY-2016   M.Sc.(Ag.) Genetics & Plant Breeding (Final) 26-MAY-2016   M.Sc. ( Agriculture ) (Agricultural Economics ) - I 26-MAY-2016   B.A. Part-II 26-MAY-2016   B.A. Part-I 24-MAY-2016   B.A. Part-III 16-MAY-2016   B.Com. Part-III 16-MAY-2016   B.Sc. Home Science-I 16-MAY-2016   B.Sc. Home Science-II 16-MAY-2016   B.Sc. Home Science-III 16-MAY-2016   M.A Economics-Final 16-MAY-2016   M.A Hindi-Prev 16-MAY-2016   M.A Hindi-Final 16-MAY-2016   M.A History-Prev 16-MAY-2016   M.A. Ancient History, Archaeology and Culture (Previous) 12-MAY-2016   M.A. Ancient History, Archaeology and Culture (Final) 12-MAY-2016   B.Com.- I Year 12-MAY-201...