can anyone leave a clue on how to convert number to word using switch case statement i can only make 1-10 number to word i just need a clue how to make hundreds to thousands thx!!!
This is a discussion on can anyone help newbie in c programming within the C Programming forums, part of the General Programming Boards category; can anyone leave a clue on how to convert number to word using switch case statement i can only make ...
can anyone leave a clue on how to convert number to word using switch case statement i can only make 1-10 number to word i just need a clue how to make hundreds to thousands thx!!!
Show us what you've done thus far and maybe we can help.
For those that don't want to download unformatted code:
Code:#include<stdio.h> main() { int x; clrscr(); printf("\n input any number to convert: "); scanf("%d",&x); switch (x) { case 0:printf("Zero");break; case 1:printf("one");break; case 2:printf("two");break; case 3:printf("three");break; case 4:printf("four");break; case 5:printf("five");break; case 6:printf("six");break; case 7:printf("seven");break; case 8:printf("eight");break; case 9:printf("nine");break; case 10:printf("ten");break; case 11:printf("hundred");break; } printf("\n"); getch(); }
how can i post it like that??hehehe
can anyone give me clue on how to make hundreds thousands number to word conversionCode:#include<stdio.h> main() { int x; clrscr(); printf("\n input any number to convert: "); scanf("%d",&x); switch (x) { case 0:printf("Zero");break; case 1:printf("one");break; case 2:printf("two");break; case 3:printf("three");break; case 4:printf("four");break; case 5:printf("five");break; case 6:printf("six");break; case 7:printf("seven");break; case 8:printf("eight");break; case 9:printf("nine");break; case 10:printf("ten");break; case 11:printf("hundred");break; } printf("\n"); getch(); }
Click on the # icon in the advanced reply window (at the top header). Put the cursor right between the [CODE] tags it will give you. Then paste your code into that area between the code tags.
The forum code looks best if you have your editor use spaces (2-5) for indentation, instead of commas.
This is what just two spaces indentation looks like (my preference):
Code:for(i=0;i<NumberToBeSorted-1; i++) { for(j=i+1;j<NumberToBeSorted;j++) { if(matrix[i] > matrix[j]) { temp = matrix[i]; matrix[i] = matrix[j]; matrix[j] = temp; } } }
well this is very simple, i hav done it till 999, u can make necessary modifications for 1000 and bigger nos..
Code:#include <stdio.h> int main() { int n=0,digits=0,m=0; clrscr(); printf("enter the no\n"); scanf("%d",&n); m=n; if(m==0) printf("Zero"); while(m!=0) { digits++; m=m/10; } if(digits==3) { digits--; m=n-(n%100); n=n%100; switch(m) { case 100: printf("one hundred "); break; case 200: printf("two hundred "); break; case 300: printf("three hundred "); break; case 400: printf("four hundred "); break; case 500: printf("five hundred "); break; case 600: printf("six hundred "); break; case 700: printf("seven hundred "); break; case 800: printf("eight hundred "); break; case 900: printf("nine hundred "); break; } } if(digits==2) { digits--; if(n>=10 && n<20) { digits=0; switch(n) { case 10: printf("ten"); break; case 11: printf("eleven"); break; case 12: printf("twelve"); break; case 13: printf("thirteen"); break; case 14: printf("fourteen"); break; case 15: printf("fifteen"); break; case 16: printf("sixteen"); break; case 17: printf("seventeen");break; case 18: printf("eithteen"); break; case 19: printf("nineteen"); break; } } else { m=n-(n%10); n=n%10; switch(m) { case 20: printf("twenty "); break; case 30: printf("thirty "); break; case 40: printf("fourty "); break; case 50: printf("fifty "); break; case 60: printf("sixty "); break; case 70: printf("seventy "); break; case 80: printf("eighty "); break; case 90: printf("ninety "); break; } } } if(digits==1) { switch(n) { case 1: printf("one"); break; case 2: printf("two"); break; case 3: printf("three");break; case 4: printf("four"); break; case 5: printf("five"); break; case 6: printf("six"); break; case 7: printf("seven");break; case 8: printf("eight");break; case 9: printf("nine"); break; } } getch(); return 0; }
Last edited by shrikanth; 08-11-2010 at 01:02 PM.