# Project 8

### Project 8

sk
##### srujash kshirsagar
srujash's Personal Gallery
##### Transcript
00:01
Discrete Mathematics
00:05
Q1. Write a C Program to convert Prefix into INFIX Expression
00:08
#include <stdio.h> #include <string.h> #include <ctype.h> #include <conio.h> char opnds[50][80],oprs[50]; int topr=-1,topd=-1; pushd(char *opnd) { strcpy(opnds[++topd],opnd); }
00:10
char *popd() { return(opnds[topd--]); } pushr(char opr) { oprs[++topr]=opr; } char popr() {
00:15
return(oprs[topr--]); } int empty(int t) { if( t == 0) return(1); return(0); } void main() { char prfx[50],ch,str[50],opnd1[50],opnd2[50],opr[2]; int i=0,k=0,opndcnt=0;
00:20
printf("Give an Expression = "); gets(prfx); printf(" Given Prefix Expression : %s\n",prfx); while( (ch=prfx[i++]) != '\0') { if(isalnum(ch)) { str[0]=ch; str[1]='\0'; pushd(str); opndcnt++; if(opndcnt >= 2) {
00:25
printf("Give an Expression = "); gets(prfx); printf(" Given Prefix Expression : %s\n",prfx); while( (ch=prfx[i++]) != '\0') { if(isalnum(ch)) { str[0]=ch; str[1]='\0'; pushd(str); opndcnt++; if(opndcnt >= 2) {
00:30
strcpy(opnd2,popd()); strcpy(opnd1,popd()); strcpy(str,"("); strcat(str,opnd1); ch=popr(); opr[0]=ch;opr[1]='\0'; strcat(str,opr); strcat(str,opnd2); strcat(str,")"); pushd(str); opndcnt-=1; }
00:35
} else { pushr(ch); if(opndcnt==1)opndcnt=0; /* operator followed by single operand*/ } } if(!empty(topd)) { strcpy(opnd2,popd()); strcpy(opnd1,popd()); strcpy(str,"(");
00:40
strcat(str,opnd1); ch=popr(); opr[0]=ch;opr[1]='\0'; strcat(str,opr); strcat(str,opnd2); strcat(str,")"); pushd(str); } printf(" Infix Expression: "); puts(opnds[topd]); getch(); }
00:46
Q2. Prove [(A→B)∧A]→B is a tautology .
00:49
As we can see every value of [(A→B)∧A]→B is "True", it is a tautology.
00:51
THANK YOU