Mageia Bugzilla – Attachment 9956 Details for
Bug 22525
Update request: gcc 5.5.0
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
Generate a number of "hailstones"
hailstones.c (text/plain), 782 bytes, created by
Len Lawrence
on 2018-02-06 13:08:00 CET
(
hide
)
Description:
Generate a number of "hailstones"
Filename:
MIME Type:
Creator:
Len Lawrence
Created:
2018-02-06 13:08:00 CET
Size:
782 bytes
patch
obsolete
>#include <stdio.h> >#include <stdlib.h> > >#define hailstone(number) (((number) % 2) == 0 ? (number) >> 1 : 3*(number) + 1) > >int main ( int argc, char * argv[ ] ) >{ > long count, m, n; > > if ( argc > 1 ) > { > if ( (n = atol( argv[1] )) <= 0 ) > { > printf( "Please supply a positive integer as a starting point\n" ); > return EXIT_FAILURE; > } > } > else > { > printf( "Please supply a positive integer as a starting point\n" ); > return EXIT_FAILURE; > } > count = 0; > if ( (m = n) == 1 ) > { > ++count; > n = hailstone( 1 ); > } > while ( n != 1 ) > { > ++count; > n = hailstone( n ); > } > printf( "%ld hailstones generated from %ld\n", count, m ); > return EXIT_SUCCESS; >}
#include <stdio.h> #include <stdlib.h> #define hailstone(number) (((number) % 2) == 0 ? (number) >> 1 : 3*(number) + 1) int main ( int argc, char * argv[ ] ) { long count, m, n; if ( argc > 1 ) { if ( (n = atol( argv[1] )) <= 0 ) { printf( "Please supply a positive integer as a starting point\n" ); return EXIT_FAILURE; } } else { printf( "Please supply a positive integer as a starting point\n" ); return EXIT_FAILURE; } count = 0; if ( (m = n) == 1 ) { ++count; n = hailstone( 1 ); } while ( n != 1 ) { ++count; n = hailstone( n ); } printf( "%ld hailstones generated from %ld\n", count, m ); return EXIT_SUCCESS; }
View Attachment As Raw
Actions:
View
Attachments on
bug 22525
: 9956 |
9958