• retagged by
2,648 views
1 1 vote
int main() {
		int a, b;
    /* Some code which initializes "a" here ... */
    if (a < 0) {
        a = -a;
    }
    b = sqrt (a);
}
  • Above code will always work for calculating the square root of any valid integer value on  a system . [T/F]

1 Answer

2 2 votes
    #include <stdio.h>
     
    int main() {
    		int a=-4, b;
        /* Some code which initializes "a" here ... */
        if (a < 0) {
            a = -a;
        }
        b = sqrt (a);
        printf("%d",b);
     
    	return 0;
    }

yes code will always work. But will not give correct output everytime. Like for - 4 it is giving square root as 2. But it is not a correct result

Position:
Show:

Related questions

1 1 vote
1 1 answer
153
153 views
khanshahima4 asked 6 days ago
153 views
1. If precedence tells me which operator has priority, and associativity tells me how to handle operators at the same level, then why do I need a separate concept called ...
13 13 votes
1 1 answer
1.3k
1.3k views
GO Classes asked Jul 2
1,253 views
Assume:$\texttt{short = 2 bytes}$, $\texttt{int = 4 bytes}$, $\texttt{char = 1 byte}$$\texttt{int}$ needs $4$-byte alignment and the final structure size is rounded to a ...
16 16 votes
2 2 answers
674
674 views
GO Classes asked Jul 2
674 views
Assume:struct Student { double gpa; }; struct Student alice; struct Student *sptr = &alice;Which of the following correctly assigns $\texttt{4.0}$ to $\texttt{alice.gpa}$...
9 9 votes
1 1 answer
496
496 views
GO Classes asked Jul 2
496 views
Consider the following code idea from the source:typedef struct { double x, y; } Point; void reset(Point p) { p.x = p.y = 0; } int main() { Point a = {12.0, 42.0}; Point ...