進階題:函數反序排列數字

#include <stdio.h>
int main()
{
int a,b=0,sum=0;
scanf("%d",&a);
while(a)
{
b=a%10;
sum=(b+sum)*10;
a=a/10;
}
printf("%d\n",sum/10);
}
進階題:2進位轉10進位
#include <stdio.h>
int main( )
{
int n;
scanf("%d",&n);
int n1=n%10;
int n2=(n/10)%10;
int n3=(n/100)%10;
int n4=(n/1000)%10;
int ans=n1*1+n2*2+n3*4+n4*8;
printf("%d\n",ans);
}
2.憤怒鳥
PImage bird,slingshot_0,slingshot_1;
void setup()
{
size(1680,720);
bird = loadImage("bird.png");
slingshot_0 = loadImage("slingshot_0.png");
slingshot_1 = loadImage("slingshot_1.png");
imageMode(CENTER);
}
float birdX = 195,birdY = 590,oldX,oldY,vx = 0,vy = 0,SSX = 200,SSY = 650;
boolean bMoving = false,bDropping = false;
void draw()
{
background(255);
if(bMoving) line(mouseX-15,mouseY+15,oldX+20,oldY+5);
image(slingshot_0,SSX,SSY,60,168);
image(bird,birdX,birdY,50,50);
image(slingshot_1,SSX,SSY,60,168);
if(bMoving) line(mouseX-15,mouseY+15,oldX-10,oldY);
strokeWeight(5);
birdX += vx;
birdY += vy;
//if (birdX > 1055 || birdX < 25) vx = -vx;
//if (birdY > 695 || birdY < 25) vy = -vy;
if (bDropping)
{
vy += 0.1;
if (birdY > 695)
{
vy = -vy;
vy += 1.5;
vx -= 0.25;
if (vy > 0) vy = 0;
if (vx < 0) vx = 0;
}
}
}
void mousePressed()
{
if (dist(mouseX,mouseY,birdX,birdY) < 50)
{
bMoving = true;
oldX = birdX;
oldY = birdY;
}
}
void mouseReleased()
{
bMoving = false;
bDropping = true;
if (dist(mouseX,mouseY,birdX,birdY) < 50)
{
vx = (oldX - mouseX)/8;
vy = (oldY - mouseY)/8;
}
}
void mouseDragged()
{
if (bMoving)
{
birdX = mouseX;
birdY = mouseY;
}
}
void setup()
{
size(1680,720);
bird = loadImage("bird.png");
slingshot_0 = loadImage("slingshot_0.png");
slingshot_1 = loadImage("slingshot_1.png");
imageMode(CENTER);
}
float birdX = 195,birdY = 590,oldX,oldY,vx = 0,vy = 0,SSX = 200,SSY = 650;
boolean bMoving = false,bDropping = false;
void draw()
{
background(255);
if(bMoving) line(mouseX-15,mouseY+15,oldX+20,oldY+5);
image(slingshot_0,SSX,SSY,60,168);
image(bird,birdX,birdY,50,50);
image(slingshot_1,SSX,SSY,60,168);
if(bMoving) line(mouseX-15,mouseY+15,oldX-10,oldY);
strokeWeight(5);
birdX += vx;
birdY += vy;
//if (birdX > 1055 || birdX < 25) vx = -vx;
//if (birdY > 695 || birdY < 25) vy = -vy;
if (bDropping)
{
vy += 0.1;
if (birdY > 695)
{
vy = -vy;
vy += 1.5;
vx -= 0.25;
if (vy > 0) vy = 0;
if (vx < 0) vx = 0;
}
}
}
void mousePressed()
{
if (dist(mouseX,mouseY,birdX,birdY) < 50)
{
bMoving = true;
oldX = birdX;
oldY = birdY;
}
}
void mouseReleased()
{
bMoving = false;
bDropping = true;
if (dist(mouseX,mouseY,birdX,birdY) < 50)
{
vx = (oldX - mouseX)/8;
vy = (oldY - mouseY)/8;
}
}
void mouseDragged()
{
if (bMoving)
{
birdX = mouseX;
birdY = mouseY;
}
}

沒有留言:
張貼留言