write a program to read a number and print in words that is
in sentence for example 21,219 then output is "twenty one
thousand and two hundred nineteen" by using only control
flow statements (only loops and switch case )?
Answer / anil kumar
import java.util.Scanner;
public class numberFormat
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter 4 digit number : ");
int num=s.nextInt();
int a=num;
a=num/1000;
if(a==1)
System.out.println("One thousand");
else if(a==2)
System.out.println("Two thousand");
else if(a==3)
System.out.println("Three thousand");
else if(a==4)
System.out.println("Four thousand");
else if(a==5)
System.out.println("Five thousand");
else if(a==6)
System.out.println("Six thousand");
else if(a==7)
System.out.println("Seven thousand");
else if(a==8)
System.out.println("Eight thousand");
else if(a==9)
System.out.println("Nine thousand");
int first=num-a*1000;
int y=first/100;
if(y==1)
System.out.println("One hundred");
else if(y==2)
System.out.println("Two hundred");
else if(y==3)
System.out.println("Three hundred");
else if(y==4)
System.out.println("Four hundred");
else if(y==5)
System.out.println("Five hundred");
else if(y==6)
System.out.println("Six hundred");
else if(y==7)
System.out.println("Seven hundred");
else if(y==8)
System.out.println("Eight hundred");
else if(y==9)
System.out.println("Nine hundred");
int second=first-y*100;
int x=second/10;
if(x==1)
System.out.println("Ten");
else if(x==2)
System.out.println("Twenty");
else if(x==3)
System.out.println("Thirty");
else if(x==4)
System.out.println("Fourty");
else if(x==5)
System.out.println("Fifty");
else if(x==6)
System.out.println("Sixty");
else if(x==7)
System.out.println("Seventy");
else if(x==8)
System.out.println("Eighty");
else if(x==9)
System.out.println("Ninty");
int third=second-x*10;
int z=third;
if (z==2)
System.out.println(" two");
else if (z==3)
System.out.println(" three");
else if (z==4)
System.out.println(" four");
else if (z==5)
System.out.println(" five");
else if (z==6)
System.out.println(" six");
else if (z==7)
System.out.println(" seven");
else if (z==8)
System.out.println(" eight");
else if (z==9)
System.out.println(" nine");
}
}
use switch case in case of if condition you will get it.
Is This Answer Correct ? | 3 Yes | 0 No |
Lists the benefits of c programming language?
Which is not valid in C? 1) class aClass{public:int x;} 2) /* A comment */ 3) char x=12;
What is #include called?
What is key word in c language?
What is structure packing ?
Write a program that accepts a string where multiple spaces are given in between the words. Print the string ignoring the multiple spaces. Example: Input: “ We.....Are....Student “ Note: one .=1 Space Output: "We Are Student"
My teacher ask to make a program that can: Insert record in front Insert record at the end Insert in between Search node record Delete record in front Delete record at the end Delete record in between Using Data structure Linked List type. But I'm really confused about the codes and I can't go through. Please help Thanks in advance. Also here is my unfinished code if someone can make changes it will be more good.
What is the use of function in c?
what will be the output for the following main() { printf("hi" "hello"); }
void main() { int s[4][2]={ {1234,56},{1212,33},{1434,80},{1312,78} }; int (*p)[2]; int i,j,*pint; for(i=0;i<=3;i++) { p=&s[i]; pint=p; printf("\n"); for(j=0;j<=1;j++) printf("%d",*(pint+j)); } } while running this program it shows a warning-suspicious pointer conversion ie pint=p; my que is why should we assign the value of p to pint again.why cant we use it directly as *(p+j)..but if i use like tat the o/p is garbage value..
write a program that print itself even if the source file is deleted?
Why do we need arrays in c?