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

Week 7

The document contains five C++ programming exercises demonstrating basic programming concepts. Exercise 1 calculates and displays the multiplication table of a user-input number, while Exercise 2 computes the sum of the digits of a given number. Exercises 3, 4, and 5 involve printing a pattern of asterisks, calculating the power of a base number, and summing user-input numbers until zero is entered, respectively.

Uploaded by

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

Week 7

The document contains five C++ programming exercises demonstrating basic programming concepts. Exercise 1 calculates and displays the multiplication table of a user-input number, while Exercise 2 computes the sum of the digits of a given number. Exercises 3, 4, and 5 involve printing a pattern of asterisks, calculating the power of a base number, and summing user-input numbers until zero is entered, respectively.

Uploaded by

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

Week 7

 Ex 1:
 #include <iostream>
 using namespace std;

 int main(){
 int number, multiplication;
 cout << "Enter number you want
multiplication: "; cin >> number;
 int i = 1;
 while (i <= 10){
 multiplication = number * i;
 cout << number << " x " << i << " =
"<< multiplication << endl;
 i += 1;
 }
 return 0;
 }
 Ex 2:
 #include <iostream>
 using namespace std;

 int main() {
 int number = 12345, sum = 0, digit;

 while (number > 0) {
 digit = number % 10;
 sum += digit;
 number /= 10;
 }

 cout << "Sum of digits: " << sum <<
endl;

 return 0;
 }
 Ex 3:
 #include <iostream>
 using namespace std;

 int main(){
 int row;
 cout << "Enter the numbar of rows: "; cin
>> row;
 int i = 1;
 while (i <= row){
 int j = 1;
 while (j <= i){
 cout << " * ";
 j++;
 }
 cout << endl;
 i++;
 }
 return 0;
 }
 Ex 4:
 #include <iostream>
 using namespace std;

 int main(){
 int i = 0, baseValue, powerValue,
result = 1;
 cout << "Enter value of base: "; cin >>
baseValue;
 cout << "Enter value of power: "; cin
>> powerValue;
 while (i < powerValue){
 result *= baseValue;
 i++;
 }
 cout << "Result of " << baseValue << "
^ " << powerValue << " = " <<result;
 return 0;
 }
 Ex 5:
 #include <iostream>
 using namespace std;

 int main(){
 int num, sum = 0;
 cout << "Enter number: "; cin >> num;
 do{
 cout << "(The input ends if you
enter 0):";
 cin >> num;
 sum += num;
 }while (num != 0 );
 cout << "The sum is: " << sum;
 return 0;
 }

You might also like