Jump to content

duvida prog.


Recommended Posts

boas eu tenho este codigo e ele dame 0 mas eu quero que ele faça 1/2 ou seja ele tem que me dar 0.5

#include <iostream>

using namespace std;

int main(){

    int a, b;

    cout << "a = ";
    cin >> a;

    cout << "b = ";
cin >> b;

cout << "a + b = " << a + b << endl;
cout << "a - b = " << a - b << endl;
cout << "a * b = " << a * b <<endl;

	cout << "a / b = " << c <<endl;

HTML Master

The programs change the world

Link to comment
Share on other sites

Quando divisão entre inteiros, o resultado é um inteiro, que representa o resultado da divisão inteira dos números.

Para forcares o resultado a aparecer com virgulas, tens de transformar em números com virgula flutuante:

cout << (float(a)/float(b)) << endl;

<Signature goes here>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.