Help with reducing the execution time

How can I reduce the execution time of this program to 0.1 miliseconds. The program is suppose to write the k number of a string that started from the number p. As an example: 9 19 39 49 69 79 99 109 129 139 159 ... is the string for the number 9, or 7 17 37 47 67 77 97 107 127 137 157 ... is the string for the number 7.
2<=p<=9.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  #include <iostream>
using namespace std;
int main()
{   int p, k, i;
    cin>>p>>k;
    for(i=2; i<=k; i++)
    {
        if(i%2==0)
            p+=10;
        else
            p+=20;
    }
    cout<<p;
    return 0;
}
It would help to get the input when the user starts the program instead of after the program starts.

Look at http://www.cplusplus.com/articles/DEN36Up4/
Last edited on
Topic archived. No new replies allowed.