|
|
Author | Message |
---|
Hari Active member
| Subject: ans this. Mon Feb 23, 2009 4:35 pm | |
| hi...
1.....please give me the java code tovfind primorialof a number...............
primorial of n is product of prime nos below or equal to n.
eg: primorial of is 2*3*5 which is 30
2.......write whether a nuimber is armstrong like.....
eg: 165033 is 16^3 + 50^3 + 33^3 |
|
| |
Anu..i luv icse...:) Active member
| Subject: Re: ans this. Mon Feb 23, 2009 8:19 pm | |
| 1)
import java.io.*; class prim { int prime=0,sum=1; public void pp(int num) { for(int j=2;j<=num/2;j++) { if(num!=j) { if(num%j!=0) { prime=0; } else if(num%j==0) { prime=1; } } } }
public void ans(int n) { for(int i=2;i<=n;i++) { pp(i); if(prime==0) { sum=sum*i; System.out.println(i+" is Prime"); } else System.out.println(i+"is not prime"); } System.out.println("Primorial of "+n+" is "+sum); } } NOTE: the first method pp() is to find whether a num is prime or not the second method ans() is to find the prime nums till n and then find their product. OUTPUT: if n=5: output is: 2 is Prime 3 is Prime 4is not prime 5 is Prime Primorial of 5 is 30
hope you understood |
|
| |
Anu..i luv icse...:) Active member
| Subject: Re: ans this. Mon Feb 23, 2009 8:24 pm | |
| hey amstrong num is a number whose sum of the cubes of its digits is equal to the number itself. |
|
| |
Anu..i luv icse...:) Active member
| Subject: Re: ans this. Tue Feb 24, 2009 1:28 am | |
| arrey..no reply? |
|
| |
Apurva Active member
| Subject: Re: ans this. Tue Feb 24, 2009 1:31 am | |
| yes anu ur rite dats armstrong bt no need 2 wry if in icse dey give ny such question den they vry well explin wt it is |
|
| |
siya Active member
| Subject: Re: ans this. Tue Feb 24, 2009 2:15 am | |
| yeah apurva is rite... |
|
| |
Hari Active member
| Subject: Re: ans this. Tue Feb 24, 2009 11:43 am | |
| so please give aprogram for armstrong nos |
|
| |
akshay Active member
| Subject: Re: ans this. Tue Feb 24, 2009 11:54 am | |
| import java.io.*; class armstrongno { public static void main() throws IOException { DataInputStream in = new DataInputStream (System.in); System.out.println("enter no."); int n =Integer.parseInt(in.readLine()); int i =n; int sum=0; int k; while (i!=0) { k = i%10; sum = sum+(k*k*k); i = i/10; } if (sum==n) System.out.println(n+" is an armstrong no."); else System.out.println(n+" is not an armstrong no."); }} |
|
| |
akshay Active member
| Subject: Re: ans this. Tue Feb 24, 2009 11:56 am | |
| pls check if it comes =) |
|
| |
Hari Active member
| Subject: Re: ans this. Tue Feb 24, 2009 12:13 pm | |
| as-24 it didnt works...its sayin 165033 not armstrong |
|
| |
Namit Active member
| Subject: Re: ans this. Tue Feb 24, 2009 1:10 pm | |
| mport java.io.*; class armstrongno { public static void main() throws IOException { DataInputStream in = new DataInputStream (System.in); System.out.println("enter no."); int num =Integer.parseInt(in.readLine());int num1=num,sum=0,rem=0;while(num1>0){rem=num1%10;sum=sum+(int)(Math.pow(rem,3));num1=num1/10;}if(sum==num){System.out.println("armstrong");elseSystem.out.println(" Not Armstrong");}} |
|
| |
Anu..i luv icse...:) Active member
| Subject: Re: ans this. Tue Feb 24, 2009 1:37 pm | |
| hey 165033=1^3 + 6^3 + 5^3 + 3^3 + 3^3 = 1+216+125+9+9 != 360 so, 165033 is nt amstrong num hari. |
|
| |
Namit Active member
| Subject: Re: ans this. Tue Feb 24, 2009 1:41 pm | |
| my dear friend hari.. da code is absolutely crct..an armstrong number is one, da sum of da cubes of invidual digits of which is qual to the number itself Ex:153 1^3+5^3+3^3=1+125+27=158 bt 165033 is nt armstrong 1^3+6^3+5^3+0^3+3^3+3^3=1+216+125+0+27+27=360 hope u get it.. |
|
| |
akshay Active member
| Subject: Re: ans this. Tue Feb 24, 2009 2:06 pm | |
| try no. 371, it'll come |
|
| |
pranjain
| Subject: Re: ans this. Thu Dec 31, 2009 1:29 pm | |
| THANK YOU ALL |
|
| |
Sponsored content
| Subject: Re: ans this. | |
|
|
|
| |
|