1 to 1000
This is an answer from the test case 1 given by PT. GDI Indonesia (http://www.ptgdi.com/#Career)... The code is in C++
//
// main.cpp
// 1 to 1000
//
// Created by Handra on 5/28/11.
// Copyright 2011 Handra. All rights reserved.
//
#include <iostream>
using namespace std ;
int main ( int argc , const char * argv [ ] )
{
unsigned int number = 1 ;
unsigned int lastStep = 3 ;
unsigned int step = 0 ;
for ( number = 1 ; number <= 1000 ; number ++ )
{
cout << number ;
step ++ ;
if ( number < 1000 && ( ( lastStep == 3 && step == 5 ) || ( lastStep == 5 && step == 3 ) ) )
{
lastStep = step ;
step = 0 ;
cout << "*" ;
}
}
return 0 ;
}
Comments
Post a Comment