Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Even and Odd numbers by Erick Benites
#import <Foundation/Foundation.h> /* Created by Erick Benites, Agoust 2018 */ @interface SorterClass:NSObject - (int *) getRandom; @end @implementation SorterClass - (int *) getRandom { static int r[10]; int i; /* set the seed */ srand( (unsigned)time( NULL ) ); for ( i = 0; i < 10; ++i) { r[i] = rand() % 100; NSLog( @"r[%d] = %d\n", i, r[i]); } return r; } - (int *) sort:(int *) numbers { int tmp; int i; int j; for ( i = 0; i < 10; ++i) { for ( j = 0; j < 10-i; ++j) { //if (numbers[j] > numbers[j+1]) { if (numbers[j] % 2) { tmp = numbers[j]; numbers[j] = numbers[j+1]; numbers[j+1] = tmp; } } } return numbers; } @end int main (int argc, const char * argv[]) { SorterClass *sorterClass = [[SorterClass alloc]init]; NSLog( @"--- Before sort ---"); int *b = [sorterClass getRandom]; int *a = [sorterClass sort:b]; NSLog( @"--- After sort ---"); int i; for ( i = 0; i < 10; ++i) { NSLog( @"r[%d] = %d\n", i, a[i]); } return 0; }
run
|
edit
|
history
|
help
0
Objective C NSSet Declaration
NSMutableStringProgram
book
shape example
Ex of String methods
fullname
02 Mostrar valor de variable entera
First Program : (+,-,*,/)
simple inheritance in objective c
aditation