#include <stdio.h>
#define MAX 10
int main( void ) {
//vetor de dimensao 10
int vetor [ MAX] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ;
//apontador para vetor
int * ptr_vetor;
//novo vetor
int novo_vetor[ MAX] ;
//apontador para novo vetor
int * ptr_novo_vetor;
//escolher numero
// int escolha = 0;
//contador
// int contador = 0;
//ponteiro apontado ao primeiro vetor
ptr_vetor = & vetor[ 0 ] ;
for ( int i = 0 ; i < MAX; i++ ) {
//mostra os valores do vetor
printf ( "\n valor : %d " , vetor
[ i
] ) ; }
printf ( "\n \n --- Ponteiro Vetor para Numero Pares ---" ) ; for ( int i = 0 ; i < MAX; i++ ) {
//escolha apenas numeros pares
if ( * ( ptr_vetor + i) % 2 == 0 ) {
//mostra os valores pares apontador ao vetor
printf ( "\n Numero Par : %d " , * ( ptr_vetor
+ i
) ) ; //adiciona o numero par ao novo vetor
novo_vetor[ i / 2 ] = * ( ptr_vetor + i) ;
}
}
ptr_novo_vetor = novo_vetor;
printf ( "\n \n \n --- Novo Vetor ---" ) ; for ( int i = 0 ; i < MAX / 2 ; i++ ) {
//mostra os valores do novo vetor
printf ( "\n valor: %d " , novo_vetor
[ i
] ) ; }
printf ( "\n \n --- Ponteiro Novo Vetor ---" ) ; for ( int i = 0 ; i < MAX / 2 ; i++ ) {
//mostra os valores do novo ponteiro
printf ( "\n Novo Vetor : %d " , * ( ptr_novo_vetor
+ i
) ) ; }
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNkZWZpbmUgTUFYIDEwCgppbnQgbWFpbih2b2lkKSB7CgogICAgLy92ZXRvciBkZSBkaW1lbnNhbyAxMAogICAgaW50IHZldG9yIFtNQVhdID0gezEsIDIsIDMsIDQsIDUsIDYsIDcsIDgsIDksIDEwfTsKICAgIC8vYXBvbnRhZG9yIHBhcmEgdmV0b3IKICAgIGludCAqcHRyX3ZldG9yOwogICAgLy9ub3ZvIHZldG9yCiAgICBpbnQgbm92b192ZXRvcltNQVhdOwogICAgLy9hcG9udGFkb3IgcGFyYSBub3ZvIHZldG9yCiAgICBpbnQgKnB0cl9ub3ZvX3ZldG9yOwogICAgLy9lc2NvbGhlciBudW1lcm8KLy8gICAgaW50IGVzY29saGEgPSAwOwogICAgLy9jb250YWRvcgovLyAgICBpbnQgY29udGFkb3IgPSAwOwoKICAgIC8vcG9udGVpcm8gYXBvbnRhZG8gYW8gcHJpbWVpcm8gdmV0b3IKICAgIHB0cl92ZXRvciA9ICZ2ZXRvclswXTsKCglwcmludGYoIlxuLS0tIFZldG9yIC0tLSIpOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBNQVg7IGkrKykgewogICAgICAgIC8vbW9zdHJhIG9zIHZhbG9yZXMgZG8gdmV0b3IKICAgICAgICBwcmludGYoIlxudmFsb3IgOiAlZCAiLCB2ZXRvcltpXSk7CiAgICB9CiAgICAKCXByaW50ZigiXG5cbi0tLSBQb250ZWlybyBWZXRvciBwYXJhIE51bWVybyBQYXJlcyAtLS0iKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgTUFYOyBpKyspIHsKICAgICAgICAvL2VzY29saGEgYXBlbmFzIG51bWVyb3MgcGFyZXMKICAgICAgICBpZiAoKihwdHJfdmV0b3IgKyBpKSAlIDIgPT0gMCkgewogICAgICAgICAgICAvL21vc3RyYSBvcyB2YWxvcmVzIHBhcmVzIGFwb250YWRvciBhbyB2ZXRvcgogICAgICAgICAgICBwcmludGYoIlxuTnVtZXJvIFBhciA6ICVkICIsICoocHRyX3ZldG9yICsgaSkpOwogICAgICAgICAgICAvL2FkaWNpb25hIG8gbnVtZXJvIHBhciBhbyBub3ZvIHZldG9yCiAgICAgICAgICAgIG5vdm9fdmV0b3JbaSAvIDJdID0gKihwdHJfdmV0b3IgKyBpKTsKICAgICAgICB9CiAgICB9CiAgICBwdHJfbm92b192ZXRvciA9IG5vdm9fdmV0b3I7CgoJcHJpbnRmKCJcblxuXG4tLS0gTm92byBWZXRvciAtLS0iKTsKIC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