0

Write an alogorithm to print first 100 numbers of following series 1,2,4,8,16.....

9th Mar 2017, 5:36 PM
Kuldeep Kaluvala
Kuldeep Kaluvala - avatar
3 odpowiedzi
+ 3
This will have a comma left over (at end). Can use an if statement to remove it. for(int i = 0; i<100;i++) System.out.print((int)Math.Pow(2,i)+",")
9th Mar 2017, 5:46 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
To be able to print so large numbers, you need BigInteger: import java.math.BigInteger; public class Program { public static final void main(String[] args) { BigInteger v = BigInteger.valueOf(1); BigInteger two = BigInteger.valueOf(2); for (int i=0; i<100; i++) { System.out.println(v); v = v.multiply(two); } } }
9th Mar 2017, 5:57 PM
Tamás Barta
Tamás Barta - avatar
0
The given series 1,2,4,8,16,32, 64,,,,, is a geometric progression series with first term as 1 and common ration 2. we get the next term by multiplying previous term by 2. Here is the c program to generate geometric progression http://www.techcrashcourse.com/2015/08/c-program-generate-geometric-series-sum.html http://www.techcrashcourse.com/2014/10/c-program-examples.html
15th Apr 2017, 8:13 AM
Arun Kumar
Arun Kumar - avatar