******************************
* * Correction * *
* * 1. Formula Summation * *
* * 2. Curly Braces * *
* * 3. Binary 1 Numbers * *
******************************
#include <stdio.h>
#include <stdlib.h>
#define N 5//calculated to 1/5
int main (void)
{Double sum1=0.0,sum2=0.0,sum=0.0;
Double i=1.0;
for (i=1;i<=n;i+=2) sum1=sum1+1.0/i;
for (i=2;i<=n;i+=2) sum2=sum2-1.0/i;
sum=sum1+sum2;
printf ("%4.4f", sum);
return 0;
}
******************
0.7833
Grouping implementation without using Flag=-flag algorithm time complexity almost space complexity add more
************************************
#include <stdio.h>
#include <stdlib.h>
int main (void)
{int x[10]={1,2,3,4,5,1,2,2};//1={2=} it a error
int i,j=0;
for (i=0;i<10;i++)
{
if (x[i]==1) {j--;if (j==-1) break;} The logic is {} and {}} are all errors
if (x[i]==1) {j + +;}
}
if (j==0) printf ("it Right");
else printf ("error");
return 0;
}
*****************************
Error
*****************************
#include <stdio.h>
#include <stdlib.h>
int main (void)
{int s=0,t=0;//s count 1 T Count 0
int x=10; 1010; s=2 1=2;
while (x)
{
Switch (x%2)
{
Case 1:s++;break;
Case 0:t++;break;
}
X=X/2;
}
printf ("Number of 1:%d", s);
printf ("Number of 0:%d", t);
return 0;
}
*******************************
Number of 1:2 0 of the number: 2
********************************
[0101] grouping sum, {} match and binary number record