Programming Solution

 Problem Statement:-

.Write collection of production rules in OPS-5 syntax to input two numbers from user and calculate sum of all the integers between the given numbers. Also trace (i.e. show status of working memory) for any one of the sample outputs given below. (Marks 20)  

Enter First Number:12

Enter Second Number:7

7 + 8 + 9 + 10 + 11 + 12 = 57

Note that output should be same if user enters 7 as first number and 12 as second number.

Enter First Number:7

Enter Second Number:12

7 + 8 + 9 + 10 + 11 + 12 = 57

Source Code:-


x = int(input("Enter the 1st number :"))
y = int(input("Enter the 2nd number :"))
if(x > y):
    temp = y
    y = x
    x = temp

sum = 0
for x in range(x, y):
    print(x, end=" + ")
    sum = sum + x
sum = sum + y
print(y, end=" = ")

int main(){
    int x, y,i,temp,sum=0;
    printf("Enter First Number\n");
    printf("Enter Second Number\n");
        printf(" + %d",i);
        sum= sum + i;
    printf(" = %d",sum);

Problem Statement 2:-

1.write a c++ program that accepts three numbers and prints "all numbers are equal" if all three numbers are equal, "All numbers are different" if all three numbers are different and
"Neither all are equal or different" 


using namespace std;
int main(){
    int x, y,z;
    cout<<"Enter three Numbers\n";
    if(x==y && y==z)
    cout<<"All Numbers are Equal\n";
    else if(x != y && y !=z)
    cout<<"All Numbers are Different\n";
    cout<<"Neighter All are equal or Different \n";

Problem Statement 3:-

write a program thats accepts three numbers from the user and prints 
"increasing" if the numbers are in increasing order, "decreasing" if the numbers are in decreasing order and 
"Neither increasing and decreasing order"



#include<iostream> using namespace std; int main(){ int x, y,z; cout<<"Enter three Numbers\n"; cin>>x>>y>>z; if(x<y && z > y){ cout<<"increasing\n"; } else if(x>y && y > z){ cout<<"Decreasing\n"; } else cout<<"Neighter Increasing or Decreasing order\n"; }

No comments:

Powered by Blogger.