请教一下我这个编程哪里错了
有一个8层灯塔,每层的灯数都是上一层的2倍,共有765盏灯。编程求最上层的灯数。#include<stdio.h>
int main(void)
{
int n,sum=0,i;
for(i=0;i<=7;i++)
{
sum=sum+(2^i)*n;
}
if(sum==765)
printf("%d",n);
}
#include <stdio.h> int calc(int i) { int j; int sum = 0; for(j = 0; j < 8; j ++) sum+=i, i*=2; return sum; } int main() { int i =1; int r; while(1) { r = calc(i); if(r >= 765) break; i ++; } if(r == 765) printf("result = %d\n", i); else printf("no such result\n"); return 0; }