Sie sind auf Seite 1von 9

THE ESPIAL- ONLINE DEBUGGING

https://docs.google.com/forms/d/1UQg5dmgnDj5uWyIE8YS44P9Nfao...

ROUND 1. 1st Slot. Name of participant

Contact No.

Email ID

Debug the following piece of code. #include<stdio.h> int main() { for(;0;) printf("\n guess"); return 0; } ---------------------Desired output: guess

The following code snippet was expected to produce the output as follows:

1 of 9

2/12/2014 10:24 PM

THE ESPIAL- ONLINE DEBUGGING

https://docs.google.com/forms/d/1UQg5dmgnDj5uWyIE8YS44P9Nfao...

#include <stdio.h> unsigned int fun(unsigned int x) { unsigned int a = x & 0xAAAAAAAA; unsigned int b = x & 055555555; a>>= 1; b <<= 1; return (a & b); } int main() { unsigned int x ; printf("%u ", fun(x)); return 0; }

Desired output: Input1: 23 output1: 43 input2: 56 output2: 52 Hint: think binary!

Correct the code. #include <stdio.h> int smallest(int x, int y, int z) { if (!y/x) return !y/z? y : z;

2 of 9

2/12/2014 10:24 PM

THE ESPIAL- ONLINE DEBUGGING

https://docs.google.com/forms/d/1UQg5dmgnDj5uWyIE8YS44P9Nfao...

return !x/z? x : z; } int main() { int x = 78, y = 88, z = 68; printf("Minimum of 3 numbers is %d", smallest(x, y, z)); return 0; }

Debug the code. #include <stdio.h> int main() { int num; scanf("%d",num); if(num|1) printf("Number is even"); else printf("Number is odd"); return 0; }

Debug the code. #include <stdio.h>

3 of 9

2/12/2014 10:24 PM

THE ESPIAL- ONLINE DEBUGGING

https://docs.google.com/forms/d/1UQg5dmgnDj5uWyIE8YS44P9Nfao...

int myfun(char *str) { int res,i =0; for (; str[i] != '\n';) res = res*10 + str[i++] ; return res; } int main() { char str[] = "89789"; int val = myfun(str); printf ("%d ", val); return 0; } Desired output: 89789

Correct the code. #include<stdio.h> int main() { int x; scanf("%d",&x); if(x|(x-1)) printf("Number is a power of 2"); else printf("Number is not power of 2"); return 0; }

4 of 9

2/12/2014 10:24 PM

THE ESPIAL- ONLINE DEBUGGING

https://docs.google.com/forms/d/1UQg5dmgnDj5uWyIE8YS44P9Nfao...

Debug the code: A perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also known as its aliquot sum). #include <stdio.h> #include <math.h> int main() { int a, num, b = 1 ; scanf("%d", num) ; for(a = 1 ; a <num/2 ; a++) { if(num % a) b +=a ; } if (b == num) printf("\n%d is a perfect number", num) ; else printf("\n%d is not a perfect number", num) ; return 0; }

The following code should count numbers from 1-1000. But there are some errors. Rectify them. #include <stdio.h> #include <stdlib.h> void main(int j) { printf("%d\n", j); (main + (exit - main)*(j/1000))(j+1); }

5 of 9

2/12/2014 10:24 PM

THE ESPIAL- ONLINE DEBUGGING

https://docs.google.com/forms/d/1UQg5dmgnDj5uWyIE8YS44P9Nfao...

The following code prints the square root of a number. #include<stdio.h> int main() { float i,j; float num; j=0.0001; scanf("%f",&num); for(i=0;i<num;i++) { if((i*i)>num) { i=i-j; break; } } printf("%0.2f",i); return 0; }

The below code should print the value of c as -4 without making any deletions in the code. #include <stdio.h>

6 of 9

2/12/2014 10:24 PM

THE ESPIAL- ONLINE DEBUGGING

https://docs.google.com/forms/d/1UQg5dmgnDj5uWyIE8YS44P9Nfao...

int main() { int b=6,a=1,2,c; printf("a : %d\n",a); c= a+~b+1; printf("%d",c); return 0; }

Below is the code to replace the entire row and column corresponding to a zero entry in a matrix with 0. Debug the code. #include <iostream> using namespace std; int main() { int a[3][3],b[10],k,z,i; for(int p=0;p<=10;p++) b[p]= -1; cout<<"Enter the array"; for(i=0;i<3;i++) { for(int j=0;j<3;j++) { cin>>a[i][j]; if(a[i][j]==0) { b[++k]=i; b[++k]=j; } } } for(i=1;i<=10;i++) { if(b[i]!=-1) { z=b[i];

7 of 9

2/12/2014 10:24 PM

THE ESPIAL- ONLINE DEBUGGING

https://docs.google.com/forms/d/1UQg5dmgnDj5uWyIE8YS44P9Nfao...

if(i%2==0) { for(int d=0;d<3;d++) a[d][z]=0; } else { for(int d=0;d<3;d++) a[z][d]=0; } } } for(i=0;i<3;i++) { for(int j=0;j<3;j++) { cout<<a[i][j]<<"\t"; } cout<<"\n"; } return 0; }

The following code should print -2. Make the required minimal editions. int main() { int a=-12; a=a>4; printf("%d",a); return 0; }

8 of 9

2/12/2014 10:24 PM

THE ESPIAL- ONLINE DEBUGGING

https://docs.google.com/forms/d/1UQg5dmgnDj5uWyIE8YS44P9Nfao...

Never submit passwords through Google Forms.


Powered by This content is neither created nor endorsed by Google. Report Abuse - Terms of Service - Additional Terms

9 of 9

2/12/2014 10:24 PM

Das könnte Ihnen auch gefallen