Question

In: Computer Science

What is the value of n after this code runs? 1 Point int n = 0;...

What is the value of n after this code runs?

1 Point

int n = 0;
int j = 7;
if ((j!=0) && (n < 25))
{
    n = 1;
    if (j > 4)
    {
        n = 2;
    }
    else
    {
        n = 3;
    }
}
else
{
    n = 4;
    if (j%2 >= 2)
    {
        n = 5;
    }
    else
    {
        n = 6;
    }
}

Solutions

Expert Solution

The value of n after this code runs is : 2

Proof :

In C language :


Related Solutions

1. What will be the value of numbers[1] after the following code is executed? int[] numbers...
1. What will be the value of numbers[1] after the following code is executed? int[] numbers = {22, 33, 44}; for(int k = 0; k < 3; k++) { numbers[k] = numbers[k] + 5; } } 2. What will be the results of the following code? final int ARRAY_SIZE = 5; double[] x = new double[ARRAY_SIZE]; for(int i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; } 3.What is the value of numbers [3] after the following line...
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i...
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i <n; ++ i) {cout << "j =" + j; j = j + 5; }}
n following code if variable n=0, a=5 and b=10 then what will be the value of...
n following code if variable n=0, a=5 and b=10 then what will be the value of variable ‘n’ after while loop executed. Show your working as well. while(n<=(a^b)) { n++; } printf("%d",n)
Please explain this code line by line void printperm(int *A,int n,int rem,int j) {    if(n==1)...
Please explain this code line by line void printperm(int *A,int n,int rem,int j) {    if(n==1)       {        for(int k=0;k<j;k++)        cout<<A[k]<<" + ";        cout<<rem<<"\n";        return;       }     for(int i=0;i<=rem;i++)    {          if(i<=rem)          A[j]=i;          printperm(A,n-1,rem-i,j+1);    } }
int value = 1; do { if (value % 2 == 0) cout << value <<...
int value = 1; do { if (value % 2 == 0) cout << value << " "; value = value + 1; } while (value % 7 != 0); cout << "\n" << value; What will be displayed?
Consider the following function: int counter( int n) { int s = 0;    for ( int...
Consider the following function: int counter( int n) { int s = 0;    for ( int i = 0; i < n; i++)             for ( int j = i; j > 0; j--)                        s = s + 1;   return s; } Part (a): How many times "s=s+1;" will be executed? Determine a precise count.  Show all your work. Part (b): What is the time complexity of the "counter" function in terms of Big-O notation? Justify and show all your work.
Consider the following C code that outlines Fibonacci function int fib (int n) { if (n...
Consider the following C code that outlines Fibonacci function int fib (int n) { if (n == 0) return 0; else if (n==1) return 1; else return fib(n-1) + fib (n-2); } For this programming assignment, write and test an ARMv8 program to find Fibonacci (n). You need to write a main function that calls the recursive fib function and passes an argument n. The function fib calls itself (recursively) twice to compute fib(n-1) and fib (n-2). The input to...
n = int(input("Enter any number: ")) sum1 = 0 for i in range(1, n): if(n %...
n = int(input("Enter any number: ")) sum1 = 0 for i in range(1, n): if(n % i == 0): sum1 = sum1 + i if (sum1 == n): print("The number is a Perfect number!") else: print("The number is not a Perfect number!") taking the code above, how would i create a new function that calls the program above and finds all perfect numbers within a certain range? the function would accept two parameters, the two ranges, and use a for...
// 1. System.out.println("1."); int max = 5; for (int n = 1; n <= max; n++)...
// 1. System.out.println("1."); int max = 5; for (int n = 1; n <= max; n++) { System.out.println(n); } System.out.println(); // 2. System.out.println("2."); int total = 25; for (int number = 1; number <= (total / 2); number++) { total = total - number; System.out.println(total + " " + number); } System.out.println(); // 3. System.out.println("3."); for (int i = 1; i <= 2; i++) { for (int j = 1; j <= 3; j++) { for (int k = 1;...
Write a full MIPS assembly code for: Function Compare(int A[][], int B[][], int M, int N,...
Write a full MIPS assembly code for: Function Compare(int A[][], int B[][], int M, int N, int i, int j, int k, int l). This function compares the elements of the array A placed between (i,j) and (k,l) with the corresponding elements of the array B placed between the same indexes. The function returns the number of elements of both matrices that coincide in the same position (c,d). That is, it is necessary to check each element A[c,d] with the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT