Posts

The python program allows the user to enter the Sales amount and Actual cost of a Product. Next, Python calculates the Loss Amount or profit Amount based on those two values using if-elif-else Statement

Image
  Write Pseudocode and draw flow chart of the following problem . The python program allows the user to enter the Sales amount and Actual cost of a Product. Next, Python calculates the Loss Amount or profit Amount based on those two values using if-elif-else Statement. Answer- Pseudocode Input the Actual cost of  Product Input the Sales Amount if(actual_cost > sale_amount):     amount = actual_cost - sale_amount     print("Total Loss Amount") elif(sale_amount > actual_cost):     amount = sale_amount - actual_cost     print("Total Profit ") else:     print("No Profit No Loss!!!") Flow chart- Python Code- #Input Actual cost of  Product actual_cost = float(input(" Please Enter the Actual cost of  Product:")) # Input Sales Amount sale_amount = float(input(" Please Enter the Sales Amount: ")) #calculate Loss Amount if(actual_cost > sale_amount):     amount = actual_cost - sale_amount     print(...

Design a Context free grammar that contains equal number of a's and b's over input {a,b} i.e. no(a)=no(b)

 Design a Context free grammar that contains equal number of a's and b's over input {a,b} i.e. no(a)=no(b) Answer- The Context free grammar (G)=(V, Σ,P,S) Where  V={S} Σ={a,b} P={S →aSbS|bSaS| λ} S={S}

Design Context free grammar

Image
Design Context free grammar  
Image
  Answer- To prove this first we construct a PDA for grammar G. Context Free Grammar (CFG) to Push Down Automata(PDA) - Let G=(V, Σ, P, S) is a context free grammar, we can construct a Push Down Automata(PDA) corresponding to given Context Free Grammar  (CFG) as follows. PDA (A)=({Q},∑,δ, Γ,q0,Z,F) Q-finite number of states ∑-input symbol δ-transition function Where δ is defined by the following rules R1: δ(q, ε,A)={(q,α)|for all A→α is in P} R2: δ(q, a,a)={(q, ε)} for each terminal a in Σ. Γ-stack symbols q0-initial state Z-initial stack symbol F-final state (F ∈ Q) Grammar G = (V, Σ, P, S) where V = {S} Σ = {a,b}  Production rule  P = {S  → aaSb|aSab|abSa|aSba|baSa|bSaa|ε} S is the start variable PDA corresponding to given CFG- PDA(A)=({q1,q2,q3},{a,b},δ,{a,b, S,$},{q1},{S},{q3}) where Q -{q1,q2,q3} ∑-{a,b} Γ-Stack symbols {a,b,S ,$} F - {q3} final state Z-{S}- Initial stack  symbol  qo-{q1 Initial state} Where δ is defined by the following rules δ(q...
  Write Python code  convert temperature from Fahrenheit to Celsius- Answer- Code- #user enter temperature in fahrenheit fahrenheit = float(input("Please enter temperature in fahrenheit: ")) # formula that convert temperature from Fahrenheit to Celsius #Celsius = (Fahrenheit – 32) * 5/9 celsius = (fahrenheit - 32) * 5/9 print('Fahrenheit temperature %.2f  in Celsius is : %0.2f Celsius' %(fahrenheit, celsius)) Output- Please enter temperature in fahrenheit: 200 Fahrenheit temperature 200.00  in Celsius is : 93.33 Celsius
Basic Programs in C Language   1.        Write a program to find the area of triangle.   Area = sqrt(s*(s-a)*(s-b)*(s-c)) #include<stdio.h> #include<conio.h> #include<math.h>   void main()   {    int a,b,c;    float s,d,area;    clrscr();    printf("Enter the sides of tringle:");    scanf("%d%d%d",&a,&b,&c);    s=(a+b+c)/2.0;    d=(s*(s-a)*(s-b)*(s-c));    area=sqrt(d);      printf("Area of:%f",area);      getch();   }   2.        Write a program to find the factorial of any number. #include<stdio.h> #include<conio.h> void main() {                 long int f=1;                 int n,i;  ...