forked from Sushreesatarupa/DSA-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparitygenerator.cpp
More file actions
48 lines (46 loc) · 942 Bytes
/
paritygenerator.cpp
File metadata and controls
48 lines (46 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
using namespace std;
int main()
{
bool type;
cout<<"Enter 0 for even parity check and 1 for odd parity check:";
cin>>type;
int s;
cout<<"Enter message length:";
cin>>s;
cout<<"Enter Message:";
int num;
cin>>num;
int input[s+1];
int c=0;
for(int i=s-1;i>=0;i--)
{
input[i]=num%10;
num/=10;
if(input[i])
c++;
}
if((type && c%2==0)||(!type && c%2==1))
input[s]=1;
else
input[s]=0;
cout<<"Message to be transmitted:";
for(int i=0;i<=s;i++)
cout<<input[i];
int msg;
cout<<"\nEnter Recieved Message:";
cin>>msg;
int c1=0;
for(int i=s;i>=0;i--)
{
int tem=msg%10;
msg/=10;
if(tem)
c1++;
}
if(!(type ^ c1%2==1))
cout<<"Received Message is Correct";
else
cout<<"Received Message is Incorrect";
return 0;
}