/* program to express 2^n in sum of n+1 terms
such that each term is a power of 2
using formula-- 2^0 + 2^1...... 2^(n-1) = 2^n - 1 */
#include <stdio.h>
#include <math.h>
int num[];
int power(int n){
for (int i = 0; i<n; i++){
num[i+1] = pow(2, i);
}
return 0;
}
int main(){
int n;
printf("Enter power of 2: ");
scanf("%d", &n);
power(n);
printf("Sum in powers of 2 is: ");
for(int i=0; i<=n; i++){
printf("%d ", num[i]);
}
}
OUTPUT - 0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 for n = 29