+ 2
Can any tell me the logic to find sum of this series 1+1÷2+1÷3+1÷4......+n and to print this series 1,1,2,3,5,8,13 in c language
3 Respostas
+ 2
well i have found it now i was preparing for my test so i wanted not to waste my time
+ 2
For series 1,1,2,3,5,8,13
int main (){
int a =0, b=1, c=0;
int limit;
printf ("Enter limit: ");
scanf ("%d", &limit);
printf ("%d ", b);
while(c < limit){
c=a+b;
printf ("%d ", c);
a=b;
b=c;
}
}
+ 1
For
1+1÷2+1÷3+1÷4......+n
int main (){
int i, n;
cin>>n;
float s=1.0;
for(i=1;i <=n;i++){
s += float (i)/i;
}
cout <<s;
}