Which Of The Following Correctly Implements Iterative Code For #1830
Which of the following correctly implements iterative code for finding power of a number?
This multiple choice question (MCQ) is related to the book/course gs gs122 Data Communication and Computer Network. It can also be found in gs gs122 Recursion - Power of a Number using Recursion in Logn Time - Quiz No.1.
Which of the following correctly implements iterative code for finding power of a number?
#include <stdio.h> int power(int x, int y) { int res = 1; while (y > 0) { if (y & 1) res = res * x; y = y >> 1; x = x * x; } return res; } int main() { int x = 3; unsigned int y = 5; printf("%d", power(x, y)); return 0; }
#include <stdio.h> int power(int x, int y) { int res = 1; while (y > 0) { if (y && 1) res = res * x; y = y >> 1; x = x * x; } return res; } int main() { int x = 3; unsigned int y = 5; printf("%d", power(x, y)); return 0; }
#include <stdio.h> int power(int x, int y) { int res = 1; while (y > 0) { if (y && 1) res = x * x; y = y >> 1; x = x * y; } return res; } int main() { int x = 3; unsigned int y = 5; printf("%d", power(x, y)); return 0; }
#include <stdio.h> int power(int x, int y) { int res = 1; while (y > 0) { if (y & 1) res = x * x; y = y >> 1; x = x * y; } return res; } int main() { int x = 3; unsigned int y = 5; printf("%d", power(x, y)); return 0; }
Similar question(s) are as followings:
Online Quizzes of gs122 Data Communication and Computer Network
Sorting - Insertion Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.3
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - LSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes