[0101] grouping sum, {} match and binary number record

Source: Internet
Author: User

******************************

* * 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.