Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C++ code
- //
- void setup()
- {
- funEvenParity();
- }
- void loop()
- {
- }
- void funEvenParity()
- {
- Serial.begin(9600);
- int sum=0;
- int mod=0;
- int e1[7]={0,1,1,1,0,0,0};
- int e1a[8]={};
- for(int i=0;i<7;i++)
- {
- sum = sum + e1[i];
- }
- mod = sum % 2;
- if(mod==0) //even already
- {
- e1a[0]=0;
- Serial.println("0");
- }
- else
- {
- e1a[0]=1;
- Serial.println("1");
- }
- Serial.print(e1a[0]);
- for(int j=0;j<7;j++)
- {
- e1a[j+1]=e1[j];
- Serial.print(e1a[j+1]);
- }
- Serial.println();
- sum=0;
- mod=0;
- for(int k=0;k<8;k++)
- {
- sum+=e1a[k];
- }
- if(sum%2==0)
- {
- Serial.println("Correct ");
- }
- else
- {
- Serial.println("!Error!!!");
- }
- }
- void funOddParity()
- {
- Serial.begin(9600);
- int sum=0;
- int mod=0;
- int e1[7]={1,0,1,1,0,1,1};
- int e1a[8]={};
- for(int i=0;i<7;i++)
- {
- sum = sum + e1[i];
- }
- mod = sum % 2;
- if(mod==0) //even already
- {
- e1a[0]=1;
- Serial.println("1");
- }
- else
- {
- e1a[0]=0;
- Serial.println("0");
- }
- Serial.print("Answer is : ");
- Serial.print(e1a[0]);
- for(int j=0;j<7;j++)
- {
- e1a[j+1]=e1[j];
- Serial.print(e1a[j+1]);
- }
- Serial.println();
- sum=0;
- mod=0;
- for(int k=0;k<8;k++)
- {
- sum+=e1a[k];
- }
- if(sum%2==0)
- {
- Serial.println("Error!!! ");
- }
- else
- {
- Serial.println("Correct ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement