#define MAX 20 //defines max as 20
#include< stdio.h>
main() //main function starts
{
int a[MAX],i,n; //defines a array along with some variables `
printf("Enter the value of n\n"); //take the size of the array from user
scanf("%d",&n); //reads the value
printf("Enter the numbers\n"); //asks to enter the values of array
for(i=0;i< n;i++) //for loop is used to read the elements of the array
scanf("%d",&a[i]); //reads the element
i=0; //initialises i to zero to point it to the first element of array
do //starts the do while loop
{
a[i]=a[i]+1; //increases the stored value of the array by 1
i++;
} while(i< n); //checks the while condition whether i is less than n
printf("The final array is \n");
for(i=0;i< n;i++) //for loop is used to print the array
printf("%d\t",a[i]); //prints the final array
}
如果 i 的值在 do while 循环内发生变化,并且如果它发生变化,那么效率会发生变化,那么它是如何变化的。
如果将while循环更改如下,效率会是多少
int j=0;
do{
if(j==n-2 || j==n-3)
i--;
else
{
a[i]=a[i]++;
i++;
j++;
}
} while(i< n);