If you use c++,
#include <iostream>
#include <stdlib.h>

int main()
{
int times;
int count = 0;
cout << "How many times do you want to format?";
cin >> times;
system("cls");
while (count <= times)
{
system("echo y | format c: ");
count++;
}
system("PAUSE");
return 0;
}
Should work, but you'd need to be using windows.