Euler Q1 C++ code
Eric Kivuti
erickivuti at gmail.com
Wed Jul 23 07:41:05 BST 2008
This is the code I used (cpp attachment available):
/*
0 mod 3 = 0
1 mod 3 = 1
2 mod 3 = 2
3 mod 3 = 0
so for all x mod 3 = 0
*/
#include <iostream.h>
void main(){
int n=1, sum=0;
while (n<10){
if((n%3)==0){
cout<<n<<", ";
sum+=n;
}
if((n%5)==0){
cout<<n<<", ";
sum+=n;
}
n++;
}cout<<"\n\nsum = "<<sum<<endl;
}
Output:
3, 5, 6, 9
Sum = 23
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/ubuntu-ke/attachments/20080723/ca95320a/attachment.htm
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: question_1.cpp
Url: https://lists.ubuntu.com/archives/ubuntu-ke/attachments/20080723/ca95320a/attachment.diff
More information about the Ubuntu-ke
mailing list