modular calculator

Back to General discussions forum

radhitya     2024-07-24 15:39:10

i dont know where is the problem.. example was ok.. but when i tried to test, i got different value..

first one i use int, but i changed because i need more data value max.. but when i use long, the problem still appears

#include <stdio.h>
int main() {

    long nilai, hasil, modular,sisa;
    char tanda;

    scanf("%ld", &hasil);

    while(1) {
    scanf(" %c", &tanda);

    if(tanda == '%') {
    scanf("%ld", &modular);
    break;
    }

    scanf("%ld", &nilai);

    if(tanda == '*') {
    hasil*= nilai;
    }

    else if ( tanda == '+') {
    hasil += nilai;
    }
    }

    sisa = hasil % modular;
    printf("%ld\n", sisa);
    return 0;
}
Rodion (admin)     2024-07-24 15:46:51
User avatar

Hi Friend!

The problem text has a link to Modular Arithmetics article. You need to read and understand it in order to solve this problem.

Values are intentionally large so that no int or long can hold it. Some careless people use endless arithmetics (e.g. in Python) but there is "advanced" version of the problem where even this won't help.

This problem requirres a bit of thinking and understanding, rather than dull coding.

radhitya     2024-07-25 02:48:37

okay admin, thank you

98ranjitdkale     2024-10-23 12:20:42

I'm not able to select a whole values as 1 input

when i tried to get input as usual like line=input().split() it only gives me 1st line and not other

plese help

Rodion (admin)     2024-10-23 22:10:32
User avatar

try more input() statements. each of them reads one line if I remember correctly.

marvish_Taylor     2024-11-17 16:23:58

looks tricky but i can try it

Please login and solve 5 problems to be able to post at forum