After an overwhelming response for 1st day we present the 2nd - TopicsExpress



          

After an overwhelming response for 1st day we present the 2nd question for Techathlon Decathlon from SegFault. Q1. The following code aims to find the greater number between a and b. Find an fix the bug in this code. The output should be like a : 10 b : 20 max(a,b) : 20 #include #define PrintInt(expr) printf("%s : %d ",expr,(expr)) int max(int x, int y) { (x > y) ? return x : return y; } int main() { int a = 10, b = 20; PrintInt(a); PrintInt(b); PrintInt(max(a,b)); } Q2. Following is a function to find whether a given integer is a power of 2 or not. Find and correct the bugs in it. #include #include void check(int n) { if(n | n+1) printf("Not a power of 2 "); else printf("Power of 2 "); } void main() { int n; scanf("%d",&n); check(n); } In debugging the above two piece of C codes you are not allowed to remove any line, you can only change it, you can add 2-3 lines more to the code if needed.Your solution must contain source code and also mentioning the error in lines(possibly as comments) .To get points the submitted source code should run and produce correct output. As mentioned the first correct entry will receive 5 Techathlon points, second entry 3, third entry 2 and after that every correct entry will get 1 point. Also the points will take you close to your prize worth Rs.1000 and give u a headstart for Techathlon.Answers should be only message on esya page, posting as comments will disqualify you. #esya13
Posted on: Sat, 03 Aug 2013 13:54:13 +0000

Trending Topics



Recently Viewed Topics




© 2015