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

Recommended Answers

Start the loop at 2 not 1. Right now its doing 88-2 = -128.

Jump to Post

All 2 Replies

Start the loop at 2 not 1. Right now its doing 88-2 = -128.

histrungalot thanks that did it...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.