#include <stdio.h>
int soma( void ) {
int valor = 0 , soma = 0 ;
printf ( "Foi escolhida a soma:\n \n " ) ; do {
printf ( "Informe os valores desejados e 0 (zero) para concluir:" ) ; soma += valor;
} while ( valor != 0 ) ;
return soma;
}
int mult( void ) {
int valor = 0 , mult = 1 ;
printf ( "Foi escolhida a multiplicacao:\n \n " ) ; do {
printf ( "Informe os valores desejados e 0 (zero) para concluir:" ) ; if ( valor == 0 ) {
break ;
}
mult *= valor;
} while ( valor != 0 ) ;
return mult;
}
int main( ) {
int op = 0 , result;
printf ( "Informe a operacao desejada soma(1) ou produto (2):" ) ;
if ( op == 1 ) {
result = soma( ) ;
}
else if ( op == 2 ) {
result = mult( ) ;
}
printf ( "O resultado foi: %d" , result
) ; return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgc29tYSh2b2lkKSB7CiAgICBpbnQgdmFsb3IgPSAwLCBzb21hID0gMDsKICAgIHByaW50ZigiRm9pIGVzY29saGlkYSBhIHNvbWE6XG5cbiIpOwogICAgZG8gewogICAgICAgIHByaW50ZigiSW5mb3JtZSBvcyB2YWxvcmVzIGRlc2VqYWRvcyBlIDAgKHplcm8pIHBhcmEgY29uY2x1aXI6Iik7CiAgICAgICAgc2NhbmYoIiVkIiwgJnZhbG9yKTsKICAgICAgICBzb21hICs9IHZhbG9yOwogICAgfSB3aGlsZSAodmFsb3IgIT0gMCk7CiAgICByZXR1cm4gc29tYTsKfQoKaW50IG11bHQodm9pZCkgewogICAgaW50IHZhbG9yID0gMCwgbXVsdCA9IDE7CiAgICBwcmludGYoIkZvaSBlc2NvbGhpZGEgYSBtdWx0aXBsaWNhY2FvOlxuXG4iKTsKICAgIGRvIHsKICAgICAgICBwcmludGYoIkluZm9ybWUgb3MgdmFsb3JlcyBkZXNlamFkb3MgZSAwICh6ZXJvKSBwYXJhIGNvbmNsdWlyOiIpOwogICAgICAgIHNjYW5mKCIlZCIsICZ2YWxvcik7CiAgICAgICAgaWYgKHZhbG9yID09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIG11bHQgKj0gdmFsb3I7CiAgICB9IHdoaWxlICh2YWxvciAhPSAwKTsKICAgIHJldHVybiBtdWx0Owp9CgppbnQgbWFpbigpIHsKICAgIGludCBvcCA9IDAsIHJlc3VsdDsKCiAgICBwcmludGYoIkluZm9ybWUgYSBvcGVyYWNhbyBkZXNlamFkYSBzb21hKDEpIG91IHByb2R1dG8gKDIpOiIpOwogICAgc2NhbmYoIiVkIiwgJm9wKTsKCiAgICBpZiAob3AgPT0gMSkgewogICAgICAgIHJlc3VsdCA9IHNvbWEoKTsKICAgIH0KICAgIGVsc2UgaWYgKG9wID09IDIpIHsKICAgICAgICByZXN1bHQgPSBtdWx0KCk7CiAgICB9CgogICAgcHJpbnRmKCJPIHJlc3VsdGFkbyBmb2k6ICVkIiwgcmVzdWx0KTsKICAgIHJldHVybiAwOwp9