Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

What is wrong in the code, I have to prove they are logically equavialent. Check it's output code, one line missing.

+5 votes
asked Jun 18, 2019 by ramesh harmel (170 points)
#include<stdio.h>

#include<conio.h>

#include<string.h>

int main()

{

char tp,tq,tr;

char a[10];

char b[10];

char c[10];

char lhs[10];

char rhs[10];

int i,j,k,l=0;

printf("\np\tq\tr\tp-->r\tq-->r\t(p-->q)^(q-->r)\tpVq\t(pvq)--->r)");

printf("\n________________________________________________________________________________________________");

for(i=0;i<=1;i++)

{

if(i==0)

   tp='T';

else

   tp='F';

for(j=0;j<=1;j++)

{

if(j==0)

  tq='T';

else

tq='F';

for(k=0;k<=1;k++)

{

if(k==0)

  tr='T';

else

  tr='F';

printf("\n%c\t%c\t%c",tp,tq,tr);

if(tp=='T'&&tr=='F')

{

a[l]='F';

printf("\t%c",a[l]);

}

else

{

a[l]='T';

printf("\t%c",a[l]);

}

if(tq=='T'&&tr=='F')

{

b[l]='F';

printf("\t%c",b[l]);

}

else

{

b[l]='T';

printf("\t%c",b[l]);

}

if(a[l]=='T'&&b[l]=='T')

{

lhs[l]='T';

printf("\t%c",lhs[l]);

}

else

{

lhs[l]='F';

printf("\t%c",lhs[l]);

}

if(tp=='F'&&tq=='F')

{

c[l]='F';

printf("\t\t%c",c[l]);

}

else

{

c[l]=='T';

printf("\t\t%c",c[l]);

}

if(c[l]=='T'&&tr=='F')

{

rhs[l]='F';

printf("\t%c",rhs[l]);

}

else

{

rhs[l]='T';

printf("\t%c",rhs[l]);

}

l++;

}

}

}

k=0;

for(i=0;i<8;i++)

{

if(lhs[i]==rhs[i])

k++;

}

if(k==8)

  printf("\nequal");

if(strcmp(lhs,rhs)!=0)

  printf("\n Both propositions are logically equivalent");

return 0;

}

1 Answer

0 votes
answered Dec 25, 2025 by Himanshu SINGH (240 points)
You're trying to prove that two logical propositions are equivalent, but there's a line missing in the output.

Upon reviewing the code, I notice that there's a potential issue in this line:

c[l]=='T';

It should be:

c[l]='T';

The single = is for assignment, whereas == is for comparison.

Also, the last if statement seems to have a contradictory message:

if(strcmp(lhs,rhs)!=0)
    printf("\n Both propositions are logically equivalent");

It should be:

if(strcmp(lhs,rhs)==0)
    printf("\n Both propositions are logically equivalent");

The strcmp function returns 0 if the strings are equal.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...