samedi 29 juillet 2023

why the output is 110 not 111? [duplicate]

#include<iostream>
#include<math.h>
using namespace std;

int main(){
    int i=0, a=0;
    while (i<3)
    {
        a = (pow(10, i)) + a;
        i++;
    }
    
    cout<<a<<endl;
    return 0;
}    

i changed the condition for loop to i<2 and it gives right output that is 11. but than i change the condition to i<3 and it gives 110 not 111. now i changed the value of a to 1 and its gives 111 but if i changed the condititon to i<2 it gives 12.

Aucun commentaire:

Enregistrer un commentaire