Rock
BAN USER// To print a triangle of stars of a given height
//======================================================
#include <iostream>
using namespace std;
void printTriangle(int height) {
for (int i = 0; i < height; ++i ) {
for ( int j = 0; j <= i; ++j ) {
cout << '*';
}
cout << "\n";
}
}
int main() {
int height;
cout<<"Enter the height of the triangle: ";
cin>>height;
printTriangle(height);
return 0;
}
//===================================================
//============================================================
//Program to check if a number is sum of its factors or not
#include <iostream>
using namespace std;
int sumofFactors(int n) {
int i=2;
int sum = 0;
int original = n;
while(n!=1) {
if(n%i==0) {
n = n/i;
sum += i;
i = 2;
}
else i++;
}
return (sum == original);
}
int main(int argc,char **argv) {
int number;
cout<<"Enter a number: ";
cin>>number;
cout<<sumofFactors(number)?"TRUE":"FALSE";
}
//============================================================
- Rock September 08, 2009