Marvin Villamizar
/
EJEMPLO_II_11_AGO_2017
dasd
main.cpp@0:81cf99bfa3ca, 2018-07-06 (annotated)
- Committer:
- dimmu8410
- Date:
- Fri Jul 06 19:25:38 2018 +0000
- Revision:
- 0:81cf99bfa3ca
asd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dimmu8410 | 0:81cf99bfa3ca | 1 | #include "mbed.h" |
dimmu8410 | 0:81cf99bfa3ca | 2 | |
dimmu8410 | 0:81cf99bfa3ca | 3 | DigitalOut led(LED2); |
dimmu8410 | 0:81cf99bfa3ca | 4 | DigitalIn push(PC_13); |
dimmu8410 | 0:81cf99bfa3ca | 5 | Serial pc(USBTX,USBRX); |
dimmu8410 | 0:81cf99bfa3ca | 6 | |
dimmu8410 | 0:81cf99bfa3ca | 7 | int count,read,prim; |
dimmu8410 | 0:81cf99bfa3ca | 8 | int primo(int number); |
dimmu8410 | 0:81cf99bfa3ca | 9 | int main() { |
dimmu8410 | 0:81cf99bfa3ca | 10 | |
dimmu8410 | 0:81cf99bfa3ca | 11 | while(1) |
dimmu8410 | 0:81cf99bfa3ca | 12 | { |
dimmu8410 | 0:81cf99bfa3ca | 13 | read=push.read(); |
dimmu8410 | 0:81cf99bfa3ca | 14 | if(read==0) |
dimmu8410 | 0:81cf99bfa3ca | 15 | { |
dimmu8410 | 0:81cf99bfa3ca | 16 | count ++; |
dimmu8410 | 0:81cf99bfa3ca | 17 | wait(0.3); |
dimmu8410 | 0:81cf99bfa3ca | 18 | } |
dimmu8410 | 0:81cf99bfa3ca | 19 | pc.printf("Numero: %d\n\r",count); |
dimmu8410 | 0:81cf99bfa3ca | 20 | wait(0.5); |
dimmu8410 | 0:81cf99bfa3ca | 21 | prim=primo(count); |
dimmu8410 | 0:81cf99bfa3ca | 22 | if(prim==0) |
dimmu8410 | 0:81cf99bfa3ca | 23 | { |
dimmu8410 | 0:81cf99bfa3ca | 24 | led=0; |
dimmu8410 | 0:81cf99bfa3ca | 25 | } |
dimmu8410 | 0:81cf99bfa3ca | 26 | else |
dimmu8410 | 0:81cf99bfa3ca | 27 | { |
dimmu8410 | 0:81cf99bfa3ca | 28 | led=1; |
dimmu8410 | 0:81cf99bfa3ca | 29 | } |
dimmu8410 | 0:81cf99bfa3ca | 30 | } |
dimmu8410 | 0:81cf99bfa3ca | 31 | } |
dimmu8410 | 0:81cf99bfa3ca | 32 | int primo(int number) |
dimmu8410 | 0:81cf99bfa3ca | 33 | { |
dimmu8410 | 0:81cf99bfa3ca | 34 | int nc=0; |
dimmu8410 | 0:81cf99bfa3ca | 35 | int res=0; |
dimmu8410 | 0:81cf99bfa3ca | 36 | for(int c=1;c<=number;c++) |
dimmu8410 | 0:81cf99bfa3ca | 37 | { |
dimmu8410 | 0:81cf99bfa3ca | 38 | res=number%c; |
dimmu8410 | 0:81cf99bfa3ca | 39 | if(res==0) |
dimmu8410 | 0:81cf99bfa3ca | 40 | nc++; |
dimmu8410 | 0:81cf99bfa3ca | 41 | if(nc>2) |
dimmu8410 | 0:81cf99bfa3ca | 42 | break; |
dimmu8410 | 0:81cf99bfa3ca | 43 | } |
dimmu8410 | 0:81cf99bfa3ca | 44 | if(nc==2) |
dimmu8410 | 0:81cf99bfa3ca | 45 | {return 1;} |
dimmu8410 | 0:81cf99bfa3ca | 46 | else |
dimmu8410 | 0:81cf99bfa3ca | 47 | {return 0;} |
dimmu8410 | 0:81cf99bfa3ca | 48 | } |