0
Write an alogorithm to print first 100 numbers of following series 1,2,4,8,16.....
3 Respuestas
+ 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)+",")
+ 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);
}
}
}
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