0

hello, i wanna ask if somebody can help me with this problem.

First code:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]){

        if(argc>1)
        {

        int i=1, zmnozek=1;

        zmnozek=atoi(argv[1]);

        for(i=1; i<argc; i++)
        {

                zmnozek*=atoi(argv[i]);

        };

        printf("Rezultat: %d\n",zmnozek);

        }else
        {
        printf("Nepravilen vnos!\n");
        };


return 0;
}

And there is the problem: When i use it to multiply positive numbers it comes out ok, but when i want to multiply for example 8 and -2 it comes out -128. Can anyone help?

Thanks in advance

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by minghags
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.