#include <iostream>
using namespace std;
void ant_move(int time){
    int size = 10;
    int ant_x = 4;
    int ant_y = 3;
    int dx = 1;//변화량
    int dy = 1;//변화량
    for(int i = 0 ; i<time; i++){
        ant_x = ant_x+dx;
        ant_y = ant_y+dy;
        if(ant_x == size){
            dx = -1;
        }
        if(ant_x == 0){
            dx = 1;
        }
        if(ant_y == size){
            dy = -1;
        }
        if(ant_y == 0){
            dy = 1;
        }}
    cout <<time<<"년 뒤에 개미는 ";
    cout <<ant_x<<","<<ant_y<<"에 있습니다.";
            }

int main() {
    ant_move(100);
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: