Lab 4:

snap1

snap2

snap3

snap4

Objective:
The objective of this lab experiment was to develop a program using either c++ or c language which convert input values to roman numerals, compute addition, subtraction, multiplication, and exponentiation.

#include
main()
{
int f;
int n;
int x;
int y;
int z;


do {
printf("\n");
printf("Choose Operation:\n");
printf("  1 = Addition\n");
printf("  2 = Subtraction\n");
printf("  3 = Multiplication\n");
printf("  4 = Power Function\n");
printf("  5 = Convert Numbers to Roman Numerals\n");
printf("  6 = EXIT\n");
printf("\n");
scanf("%d",&x);
 f = x;

    if (x==1){
        printf("    ADDITION\n");
        do {
        printf("Enter first value:    ");
        scanf("%d", &y);
        printf("Enter second value:   ");
        scanf("%d", &z);
        x = y +z;

        if (x>=65536) {
                printf("     **Values entered will cause overflow...**\n");
            }

            else {
                printf("Answer: %d\n", x);
            }
        }
        while(x>=65536);
        } // ends else if x = 1 statement
        

    else if (x==2){
        printf("    SUBTRACTION\n");
        do {
        printf("Enter first value:   ");
        scanf("%d", &y);
        printf("Enter second value:   ");
        scanf("%d", &z);
        x = y -z;

        if (x>=65536) {
                printf("     **Values entered will cause overflow...**\n");
            }

            else {
                printf("Answer: %d\n", x);
            }
        }
        while(x>=65536);
        } // ends else if x = 2 statement


    else if (x==3){
        printf("    MULTIPLICATION\n");
        do {
        printf("Enter first value:   ");
        scanf("%d", &y);
        printf("Enter second value:   ");
        scanf("%d", &z);

        n = y;
            while (z>1){
                
                y = y+n;
                z--;
                }


            if (y>=65536) {
                printf("     **Values entered will cause overflow...**\n");
            }

            else {
                printf("Answer: %d\n", y);
            }
        }
        while(y>=65536);
        } // ends else if x = 3 statement


    else if (x==4){
                
        printf("    POWER\n");
        do {
        printf("Enter first value:   ");
        scanf("%d", &y);
        printf("Enter power value:   ");
        scanf("%d", &z);
            
        n = y;
            while (z>1){
                
                y = y*n;
                z--;
                }
            
            if (y>=65536) {
                printf("     **Values entered will cause overflow...**\n");
            }

            else {
                printf("Answer: %d\n", y);
            }
        }
        while(y>=65536);
        } // ends else if x = 4 statement

    else if (x==5){
        printf("    CONVERSION\n");
        do {
        printf("Enter Number You Wish To Convert:   ");
        scanf("%d", &y);
        
        if (y>=65536) {
                printf("     **Values entered will cause overflow...**\n");
            }
            
        else {
            
            while(y > 0){ 
                n=y;
                if(y >= 100){
                    y = n -100; // sub(100, eax);
                    
                    printf("C");
                    
                    } 
                else if(y >= 99){
                    y = n-99; //sub(99, eax);
                    printf("IC");
                    
                    }
                else if(y >= 90){
                    y = n-90; //sub(90, eax);
                    printf("XC");
                    
                    }
                else if(y >=50){
                    y = n-50; //sub(50, eax);
                    printf("L");
                    
                    }
                else if(y >= 49){
                    y = n-49; //sub(49, eax);
                    printf("IL");
                    
                    }
                else if(y >= 40){
                    y = n-40; //sub(40, eax);
                    printf("XC");
                    
                    }
                else if(y >= 10){
                    y = n - 10; //sub(10, eax);
                    printf("X");
                    
                    }
                else if(y >= 9){
                    y = n-9; //sub(9, eax);
                    printf("IX");
                    
                    }
                else if(y >=5){
                    y = n-5; //sub(5, eax);
                    printf("V");
                    
                    }
                else if(y>=4){
                    y = n-4; //sub(4, eax);
                    printf("IV");
                    
                    }
                else if(y >= 1){
                    y = n-1; //sub(1, eax);
                    printf("I");
                    
                    }
                
                } //ends while
        } // ends else statement
            
        }
        while(y>=65536);
        
        } // ends else if x = 5 statement
            
        
}
while (f < 6);
 
} // closes program

Leave a Reply

Your email address will not be published. Required fields are marked *