Se requiere un algoritmo que permita solicitar al usuario dos nmeros (ambos entre 1 y
100). Si alguno de los nmeros no est en ese rango, se muestra error y finaliza el
algoritmo. Si los dos nmeros estn en el rango, el algoritmo debe mostrar la suma de
los mltiplos de 3 que hay en ese rango y contar los que son impares en ese rango.
NOTA: Es libre usar la estructura Repetir Para (una de las dos) para resolver el
problema, adems mostrar una prueba de escritorio completa como se hizo en clase.
Realice una prueba ingresando primero 15 y luego 30 y primero 30 y luego 15
(funcionara igual).
SOLUCION
CODIGO #1
int x,y;
int i,j;
int a,velA;
int b,velB;
void setup(){
size(500,600);
x= width;
y= height;
a= 475;
b= 175;
velA= 0;
velB= 2;
}
void draw(){
background(255,0,255);
stroke(127);
strokeWeight(6);
fill(255,0,0);
rect(100,200,350,300);
//circulos
stroke(127);
strokeWeight(3);
fill(0,255,0);
for(i=25;i<=500;i=i+50){
ellipse(i,575,50,50);
}
//triangulos
stroke(127);
strokeWeight(4);
fill(0);
for(i=0;i<=500;i=i+50){
triangle(0,i,50,i,50,i+50);
}
//cuadrados
stroke(255);
strokeWeight(2);
fill(0,0,255);
for(i=100;i<=400;i=i+75){
for(j=225;j<=425;j=j+100){
rect(i,j,50,50);
}
}
//cuadrilateros
stroke(127);
strokeWeight(4);
for(i=100;i<=500;i=i+50){
if(i%4==0){
fill(255);
}
else{
fill(255,255,0);
}
quad(i,0,i+50,0,i,150,i-50,150);
}
//movimiento
stroke(0);
strokeWeight(1);
fill(0,255,255);
ellipse(a,b,50,50);
a=a+velA;
b=b+velB;
if((a==475)&&(b>525)){
a=475;
b=525;
velA=-2;
velB=0;
}
if((a<75)&&(b==525)){
a=75;
b=525;
velA=0;
velB=-2;
}
if((a==75)&&(b<175)){
a=75;
b=175;
velA=2;
velB=0;
}
if((a>475)&&(b==175)){
a=475;
b=175;
velA=0;
velB=2;
}
}
CODIGO #2
//taller 3 algoritmia y programacion
int x,y;
int i,j;
int a,velA;
int b,velB;
void setup(){
size(800,700);
x= width;
y= height;
a= 0;
b= 100;
velA=4;
velB=0;
}
void draw(){
background(0,0,255);
stroke(127);
strokeWeight(6);
fill(255,255,0);
rect(50,150,550,500);
// rectangulos laterales
stroke(127);
strokeWeight(4);
fill(0,255,0);
for(i=100;i<=550;i=i+150){
rect(650,i,150,100);
}
//triangulos
stroke(127);
strokeWeight(3);
for(i=0;i<=750;i=i+50){
if(i%4==0){
fill(255,0,0);
}
else{
fill(0);
}
triangle(i,0,i+50,100,i,100);
}
//circulos
stroke(127);
strokeWeight(2);
fill(0,255,255);
for(i=75;i<=575;i=i+100){
for(j=175;j<=625;j=j+75){
ellipse(i,j,50,50);
}
}
//movimiento
stroke(255);
strokeWeight(1);
fill(255,0,255);
rect(a,b,50,50);
a= a+velA;
b= b+velB;
if((a>600)&&(b==100)){
a= 600;
b= 100;
velA= 0;
velB= 4;
}
if((a==600)&&(b>650)){
a=600;
b=650;
velA=-4;
velB=0;
}
if((a<0)&&(b==650)){
a=0;
b=650;
velA=0;
velB=-4;
}
if((a==0)&&(b<100)){
a=0;
b=100;
velA=4;
velB=0;
}
}