How to access any variable name according to loop index

前端 未结 5 1823

I have some integer variables, I named them n0 to n9. I want to access them using a loop. I tried this code to do that:

int n0 = 0, n1          


        
5条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 17:42

    int n[10] = {0};
    /*or you can initilize like this also , this will make all the elements 0 in array*/
    
    for(i = 0; i < 10; i++){
        if(digit == 1){
            n[i] = n[i] + 1;
        }               
    }
    

    Try this and let me know

提交回复
热议问题