#include <stdio.h>
typedef char bit;
bit jk(bit J,bit K,bit Q)
{
return J&~(Q)|Q&~(K);
}
int main()
{
int i,j,k,a,res=0;
int x,y,z;
char b;
printf("1.Truth Table of JK flip flop");
printf("\n2.I/O operation\n");
printf("Enter your choice: ");
scanf("%d",&a);
switch(a)
{
case 1:
printf("J K Q(t) | Q(t+1)\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
res=jk(i,j,k);
printf("%d %d %d |",i,j,k);
printf(" %d\n",res);
}
}
}
break;
case 2:
printf("Enter the value of J,K,Q(t):");
scanf("%d%d%d",&x,&y,&z);
res=jk(x,y,z);
printf("Q(t+1)= %d\n\n",res);
break;
default:
printf("invalid input");
}
printf("do you want to continue(Y/N):");
scanf(" %c",&b);
if(b=='Y'||b=='y')
{
main();
}
else{
return 0;
}
}
Output:
1. Truth Table of JK flip flop
2.I/O operation
Enter your choice: 1
J K Q(t) | Q(t+1)
0 0 0 | 0
0 0 1 | 1
0 1 0 | 0
0 1 1 | 0
1 0 0 | 1
1 0 1 | 1
1 1 0 | 1
1 1 1 | 0
do you want to continue(Y/N): y
1. Truth Table of JK flip flop
2.I/O operation
Enter your choice: 2
Enter the value of J, K & Q(t): 1 1 1
Q(t+1)= 0
do you want to continue(Y/N): n
--------------------------------
Process exited after 25.18 seconds with return value 0
Press any key to continue . . .
Program in C++:
#include <iostream>
using namespace std;
typedef char bit;
bit jk(bit J,bit K,bit Q)
{
return J&~(Q)|Q&~(K);
}
int main()
{
int i,j,k,a,res=0;
char b;
cout<<"1.Truth Table of JK flip flop\n";
cout<<"2.I/O operation\n";
cout<<"Enter your choice: ";
cin>>a;
switch(a)
{
case 1:
cout<<"J K Q(t) | Q(t+1)"<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
res=jk(i,j,k);
cout<<i<<" "<<j<<" "<<k<<" ";
cout<<" | "<<res<<endl;
}
}
}
break;
case 2:
int j,k,l;
cout<<"Enter the value of J,K & Q(t):";
cin>>j>>k>>l;
res=jk(j,k,l);
cout<<"Q(t+1)= "<<res<<"\n\n";
break;
default:
cout<<"invalid input";
}
cout<<"do you want to continue(Y/N): ";
cin>>b;
if(b=='Y'||b=='y')
{
main();
}
else{
return 0;
}
}
Output:
1. Truth Table of JK flip flop
2.I/O operation
Enter your choice: 1
J K Q(t) | Q(t+1)
0 0 0 | 0
0 0 1 | 1
0 1 0 | 0
0 1 1 | 0
1 0 0 | 1
1 0 1 | 1
1 1 0 | 1
1 1 1 | 0
do you want to continue(Y/N): y
1. Truth Table of JK flip flop
2.I/O operation
Enter your choice: 2
Enter the value of J, K & Q(t): 1 1 1
Q(t+1)= 0
do you want to continue(Y/N): n
--------------------------------
Process exited after 25.18 seconds with return value 0
Press any key to continue . . .
Algorithm:
STEP 1: Start
STEP 2: Define 'jk' function
STEP 3: Perform the operation (J&~(Q)|Q&~(K)) where J, Q, K are one bit binary number
STEP 4: Invoke main function
STEP 5: Initialize variables
STEP 6: Print "Enter your choice"
STEP 7: Input choice 1 or 2
STEP 8: If the user enters 1 or 2 then follow the below steps else flow goes to default case & exit the program Switch(operator)
STEP 8.a case 1: STEP 8.a.1: Check for condition (i<2), if Condition is true, go to step 7 otherwise go to step 12
STEP 8.a.2: Check for condition (j<2), if Condition is true, go to further step otherwise go to step 6
STEP 8.a.3: Check for condition (k<2), if Condition is true, go to further steps otherwise go to step 7
STEP 8.a.4: Call 'jk' function for value of Q(t+1)
STEP 8.a.5: Print i,j,k and Q(t+1) for truth table
STEP 8.b case 2: STEP 8.b.1: Input three one bit binary number
STEP 8.b.2: Call 'jk' function for value of Q(t+1)
Comments :
Post a Comment