4. A Shorter Three
by CodeChum Admin
Numbers in threes are awesome! But the one last time was too lengthy to look at, so I just want to view it in a shorter but still readable format.
You okay with this task?
Instructions:
Print out all numbers from 1 to 100 that is divisible by 3 using a for loop just like the last problem, but this time, with each number only separated by the space like that of the sample output.
Output
A line containing integers divisible by 3 separated by a space.
3·6·9·12·15·18·21·24·27·30·33·36·39·42·45·48·51·54·57·60·63·66·69·72·75·78·81·84·87·90·93·96·99
#include <iostream>
using namespace std;
int main(){
for(int i = 1; i <= 100; i++){
if(!(i % 3)){
cout<<i<<" ";
}
}
return 0;
}
Comments
Leave a comment