0 votes 0 votes What is the value of p and q at the end? #include<stdio.h> int main() { int n=1024; int p=0,q=0; int i,j; for( i = 1;i<=n;i=2*i) p=p+5; for(j = 1;j<=p;j=2*j) q=q+7; printf(" %d\n %d\n",p,q); } Please explain briefly. Siddharth Bhardawaj asked Jul 1, 2018 • edited Jul 1, 2018 by Siddharth Bhardawaj Siddharth Bhardawaj 344 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply Anu007 commented Jul 1, 2018 reply Follow Share for( i = 1;i <= n;i = 2*i) p = p+5; an output: of this loop run log2(1024) +1= 5+5+5+5+5+5+5+5+5+5+5= 55 for(j = 1;j <= 55;j = 2*j) q = q+7; an output: of this loop log2(55)+1 = 7+7+7+7+7+7 = 42 printf(" %d\n %d\n",p,q); 3 votes 3 votes Shaik Masthan commented Jul 1, 2018 reply Follow Share i hope you mistakenly typed as for( j = 1;i <= p; j = 2*j ) insteadof for ( j = 1; j <= p ; j = 2*j ) if it is not mistake, q is never executes. for finding answer for your question, see the in the perspective of Algorithms. p is incrementing by 5 ---- ( log n + 1) times -----> plus 1 is due to equal operator in the condition q is incrementing by 7 --- ( log p + 1 ) times -----> plus 1 is due to equal operator in the condition 1 votes 1 votes Please log in or register to add a comment.