Skip to content
EMPS intranet

Back to top
Hi!   Hi!           Start main()

Try stepping through the code


  Value and type of last evaluated expression: Address of array element: Address of array elementx:  (none)

Your browser does not support the canvas element which will make some the features unavailable.

If you are using Internet Explorer within the University of Exeter try going to the Settings menu (probably the gear shape at the top right of this page), selecting "Compatibility View settings", unchecking "Display intranet sites in Compatibility View" and reloading this page.

Code

 Header...
// // Print the lowest factor of an integer or say that it is prime. // Written to illustrate the while() loop // The basic algoritm is to try every possible factor up to the square // root of the number being looked at (the target) //
int main(){
  ...
» int target, factor, maxfactor; » target=55; » maxfactor=sqrt(target);// Largest factor we need to try » factor=2; » while (target%factor!=0&&factor<=maxfactor) ++factor;// factor = factor + 1 » if (factor>maxfactor) printf("%d is prime\n", target); else printf("\t%d is not prime, its lowest factor is %d\n", target, factor); » return 0;
}

Data

target (int)   factor (int)
128   132
134536827
  
134536631
maxfactor (int)
136
1

Memory

main()

128
129
130
131
132
133
134
135
target = 134536827
factor = 134536631
136
137
138
139
maxfactor = 1

NB: the actual memory address of each variable is the
address shown plus 4292398256 (0xFFD8CCB0).

Show Advanced options

.
Show output (Before looking at the output, work out what you think it put should be and see if you are right.)

Output

	55 is not prime, its lowest factor is 5
                                                                                                                                                                                                                                                                       

Validate   Link-check © Copyright & disclaimer Share
Back to top