in Programming in C edited by
972 views
1 vote
1 vote

Consider the following C code:

int getNextGap(int gap){
    gap=(gap*10)/13;
    if(gap<1)return 1;
    return gap;
}
void mystery(int a[ ],int n){
    int gap=n;
    bool red=true;
    while(gap!=1||red==true){
        gap=getNextGap(gap);
        red=false;
        for(int i=0;i<(n-gap);i++){
            if(a[i]>a[i+gap]){
                swap(a[i],a[i+gap]);
                red=true;
            }
        }
    }
}

The array $A=\left \{ 9,4,-1,3,5,7,99,-33,104 \right \}$ passed in the above function , and n is number of array elements, then what output  will print at last?


I mostly stuck how bool function working here. Plz help me out, how program executing:(

in Programming in C edited by
by
972 views

4 Comments

Yes you are right

I forgot that it was OR condition in while loop
1
1
Here I would say two parts, the function and the statements inside if branch. Also the condition in while loop
1
1
moved by
There is no bool datatype in C then how the code will execute?
0
0

Please log in or register to answer this question.

Related questions