0% found this document useful (0 votes)
44 views

Cales - ComProg2 - Activity 6

The document contains 9 C++ programs written by Rose Mae D. Cales to demonstrate basic programming concepts like loops, conditional statements, functions etc. Each program contains the code, input/output and the programmer's name. The programs include calculating sum of first 10 numbers, multiplication table, factorial, power, reversing digits, separating even and odd sums, checking prime numbers and adding two numbers.

Uploaded by

Rose Mae Cales
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Cales - ComProg2 - Activity 6

The document contains 9 C++ programs written by Rose Mae D. Cales to demonstrate basic programming concepts like loops, conditional statements, functions etc. Each program contains the code, input/output and the programmer's name. The programs include calculating sum of first 10 numbers, multiplication table, factorial, power, reversing digits, separating even and odd sums, checking prime numbers and adding two numbers.

Uploaded by

Rose Mae Cales
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Rose Mae D.

Cales
ICT 11 - 1

Activity 6

1.

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input
loop */

int main(int argc, char** argv) {

cout<<"\n Numbers from 1 - 10"<<endl;


cout<<"________________________"<<endl;

for (int i=1; i<=10; ++i){


cout<<"\n "<<i<<" "<<endl;
}

cout<<"--------------------------------"<<endl;
cout<<"Programmer's Name: Rose Mae D. Cales";
return 0;
}
2.

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input
loop */

int main(int argc, char** argv) {

int num, sum;


sum=0;

cout<<"\n\t\t\tCalculating the Sum of First 10 Natural Number"<<endl;


cout<<"\n\t\tEnter a positive integer: ";
cin>>num;

for (int count=1; count<=num; ++count){


sum+=count;
}

cout<<"\n\t\tSum = "<<sum<<endl;

cout<<"\n--------------------------------"<<endl;
cout<<"Programmer's Name: Rose Mae D. Cales";
return 0;
}
3.

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input
loop */

int main(int argc, char** argv) {

int num;

cout<<"\n\tEnter a positive integer: ";


cin>>num;

if (num<=0){
cout<<"\n\tInvalid. Please input a positive integer.";
}

cout<<"___________________________________________________________________";
cout<<" "<<endl;
cout<<"\n\t\tThe multiplication table of "<<num<<endl;
for (int i=1; i<=10; ++i){
cout<<"\n\t"<<num<<" x "<<i<<" = "<<num*i<<endl;
}

cout<<"\n--------------------------------"<<endl;
cout<<"Programmer's Name: Rose Mae D. Cales";
return 0;
}
4.

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input
loop */

int main(int argc, char** argv) {

int num;
int f=1;

cout<<"\n\t\t\tFinding the Factorial Value"<<endl;


cout<<"\n\t\tEnter a number: ";
cin>>num;

for (int i=1; i<=num; ++i){


f*=i;
}

cout<<"\n\t\tThe factorial of " <<num<< " is: " <<f<<endl;

cout<<"\n--------------------------------"<<endl;
cout<<"Programmer's Name: Rose Mae D. Cales";

return 0;
}
5.

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input
loop */

int main(int argc, char** argv) {

int base, exponent, i, result=1;

cout<<"\n\t\tEnter the base number: ";


cin>>base;

cout<<"\n\t\tEnter the exponent: ";


cin>>exponent;

for(i=0; i<exponent; ++i){


result=result*base;
}

cout<<"\n\t\t"<<base<< " raised to the power of "<<exponent<<" is: "<<result<<endl;

cout<<"\n--------------------------------"<<endl;
cout<<"Programmer's Name: Rose Mae D. Cales";
return 0;
}
6.

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input
loop */

int main(int argc, char** argv) {

int n, rn=0;

cout<<"\n\t\t\tReveresed Numbers"<<endl;
cout<<"\n\t\tEnter an integer: ";
cin>> n;

while (n!=0){
rn=(rn*10)+(n%10);
n/=10;
}

cout <<"\n\t\tReversed: "<<rn<<endl;

cout<<"\n--------------------------------"<<endl;
cout<<"Programmer's Name: Rose Mae D. Cales";

return 0;
}
7.

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input
loop */

int main(int argc, char** argv) {

int n, sumeven=0, sumodd=0;

cout<<"\n\t\tEnter a set of integers (enter 0 to stop):";

do{
cin>>n;

if (n%2==0){
sumeven+=n;
} else {
sumodd+=n;
}

} while (n!=0);

cout<<"\n\t\tSum of even integers: "<<sumeven<<endl;


cout<<"\t\tSum of odd integers: "<<sumodd<<endl;

cout<<"\n--------------------------------"<<endl;
cout<<"Programmer's Name: Rose Mae D. Cales";
return 0;
}
8.

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input
loop */

int main(int argc, char** argv) {


int number;
bool isPrime = true;

cout<<"\n\t\t\tPrime Numbers"<<endl;
cout<<"\n\t\tEnter a positive integer: ";
cin >> number;

if (number <= 1) {
isPrime = false;
} else {
for (int i = 2; i * i <= number; ++i) {
if (number % i == 0) {
isPrime = false;
break;
}
}
}

if (isPrime) {
cout<<"\t\t"<<number<<" is a prime number."<<endl;
} else {
cout<<"\t\t"<<number<<" is not a prime number." <<endl;
}

cout<<"\n--------------------------------"<<endl;
cout<<"Programmer's Name: Rose Mae D. Cales";
return 0;
}
9.

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input
loop */

int main(int argc, char** argv) {

char choice;
int number1, number2;
int sum;

cout << "\n\t\t\tSum of Two Numbers" << endl;

do {
cout << "\n\t\tEnter the first number: ";
cin >> number1;

cout << "\t\tEnter the second number: ";


cin >> number2;

sum = number1 + number2;

cout << "\n\t\tThe sum of " << number1 << " and " << number2 << " is: " << sum <<endl;

cout << "\n\t\t\tDo you want to perform the operation again? (Y/N): ";
cin >> choice;
} while (choice == 'Y' || choice == 'y');
cout<<"\n--------------------------------"<<endl;
cout<<"Programmer's Name: Rose Mae D. Cales";

return 0;
}

You might also like