Sei sulla pagina 1di 4

Malveda, Evan Joseph R.

BSIT 1202

Data Structures and Algorithm

Write a pseudocode for this problems.


1. S=(A+B+C)/Y
Step 1: Start
Step 2: Input A
Step 3: Input B
Step 4: Input C
Step 5: sum=A+B+C
Step 6: Input Y
Step 7: S=sum/Y
Step 8: Result
Step 9: End

2. Convert from Celsius to Fahrenheit


(multiply by 9, then divide by 5, then add 32)
Step 1: Start
Step 2: Input celsius
Step 3: Celsius*9/5+32
Step 4: Result
Step 5: End

3. Area of circle
Step 1: Start
Step 2: Input value of radius (r)
Step 3: Calculate area using pi*r ²
Step 4: Output area
Step 5: End

4. Volume of sphere
Step 1: Start
Step 2: Input value of radius (r)
Step 3: Calculate volume of sphere using 4/3*pi*r ³
Step 4: Output volume
Step 5: End

5. Average speed = distance traveled /time taken


Step 1: Start
Step 2: Input distance traveled (d)
Step 3: Input time taken (t)
Step 4: Compute using d/t
Step 5: Result
Step 6: End

Create a program.
1. Write a program in C++ to find the first 10 natural numbers.
#include <iostream>
using namespace std;
int main()
{
int x;
cout << "The natural numbers are: \n";
for (x = 1; x <= 10; x++)
{
cout << x << " ";
}
cout << endl;
return 0;
}

2. Write a program in C++ to find the sum of first 10 natural numbers


#include <iostream>
using namespace std;
int main()
{
int x, sum=0;
cout << "The natural numbers are: \n";
for (x = 1; x <= 10; x++)
{
cout << x << " ";
sum = sum + x;
}
cout << endl;
cout << "The sum of the natural numbers are " << sum << endl;
cout << endl;
return 0;
}

3. Write a program in C++ to display n terms of natural number and their sum.
#include<iostream>
using namespace std;
int main()
{
int b, x, sum=0;
cout<<"Input a number of terms: ";
cin>>x;
for (int b=1; b <= x; b++)
{
cout << b << " ";
sum = sum + b;
}
cout << endl;
cout << "The sum of the natural numbers are " << sum << endl;
return 0;
}

4. Write a program in C++ to calculate the sum of the series


(1*1)+(2*2)+(3*3)+(4*4)+(5*5)+…+(n*n).
#include <iostream>
using namespace std;

int main()
{
int x, b, sum = 0;
cout << "Enter the value for the nth term: ";
cin >> b;

for (x = 1; x <= b; x++)


{
sum += x * x;
cout << x << "*" << x << " = " << x * x << endl;
}
cout << "The sum of the series is: " << sum << endl;
return 0;
}

5. Write a program in C++ to calculate the series (1)+(1+2)+(1+2+3)+(1+2+3+4)+…


+(1+2+3+4+…+n).
#include <iostream>
using namespace std;
int main()
{
int x, y, b, sum = 0, sm;
cout << "Enter the value for nth term: ";
cin >> b;
for (x = 1; x <= b; x++)
{
sm = 0;
for (y = 1; y <= x; y++)
{
sum += y;
sm += y;
cout << y;
if (y < x)
{
cout << "+";
}
}
cout << " = " << sm << endl;
}
cout << "The sum of the series is: " << sum << endl;
return 0;
}

6. Write a program in C++ to print a square pattern with # character.


#include<iostream>
using namespace std;
int main()
{
int r, w, x;
cout << "Print a pattern like square with # character: \n";
cout << "Input the desired number of characters for a side: ";
cin >> x;

for(r=1; r<=x; ++r)


{
for(w=1; w<=x; ++w)
{
cout << "# ";
}
cout << "\n";
}
return 0;
}

Multiplication Table
#include<iostream>
using namespace std;
int main()
{
cout << "Multiplication table" << endl;
cout << " 1 \t2\t3\t4\t5\t6\t7\t8\t9" << endl;
cout << "" << endl;

for(int x = 1; x < 10; x++)


{
cout << x << ": ";
for(int y = 1; y < 10; y++)
{
cout << y * x << '\t';
}
cout << endl;
}
return 0;
}

Potrebbero piacerti anche