0% found this document useful (0 votes)
28 views8 pages

Machote Programacion Reparado

This document describes several programming problems and their solutions in C++. It includes flowcharts and pseudocode for programs using different loops and conditional statements like if/else, for loops, and while loops. The programs prompt the user for input, perform processes like comparisons, and output results such as whether a number is positive or negative, the largest of three numbers, or a multiplication table.

Uploaded by

kaneki
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)
28 views8 pages

Machote Programacion Reparado

This document describes several programming problems and their solutions in C++. It includes flowcharts and pseudocode for programs using different loops and conditional statements like if/else, for loops, and while loops. The programs prompt the user for input, perform processes like comparisons, and output results such as whether a number is positive or negative, the largest of three numbers, or a multiplication table.

Uploaded by

kaneki
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/ 8

Polytechnic University of Amozoc. Bank of Programs.

Programming 1

Bank of Exercise.

Polytechnic University of Amozoc.


Summary This document describes each program with the D. For Loop.
function it performs as well as the flow chart of each with In this program C ++ should be coded to work
pseudocode. It shows inputs, processes and outputs. correctly and describe its function.
Index of Terms Else, If, while, C ++, Flow digrama, E. For.
pseudocode, inputs, processes, outputs. This Program to print half pyramid using *.
Modify this program to print half pyramid using
I. INTRODUCTION.
numbers.
If: It is used to assert a true condition.
ForLoop: This statement is used to add cycles as the counter i. F. do...while Loop.
While: While a condition is true this statement is executed, Encode this program in C ++ and explain what its
otherwise it executes another condition. function.
Goto salto: It is used to skip a sentence in case it is true or not.
Break: It is a break from the program.

II. PROBLEM STATEMENT. G. C++ break.


Encode this program in C++ and explain what its
A. If else statement. fuction .Modifies the program to use breackif
In this program C ++ should be coded to work negative numbers are entered.
correctly and describe its function.
H. C++ continue.
B. If, if else and Nested ifelse. C++ continue. Encode this program in C ++ and
In this program C ++ should be coded to work explain what its function.
correctly and describe its function. Modify the program so that it shows the numbers
from 1 to 110 except the even
C. If, if else and Nested ifelse.
Numbers.
In this program C ++ should be coded to work
correctly and describe its function. I. For.
Encode a program to find sum of series 1 + 2 + 3
++ n.
J. Float.
Encode a program to print following series using
function: x + x^3/3! + x^5/5!
+.+ x^n/n!..
K. For.
Prints the successions of 1 * 2 stopping until the
number 128.
L. For.
Given an exponent does the sum of the result.

Profesor Dr. Gabriel Romero Rodrguez


Polytechnic University of Amozoc. Bank of Programs. Programming 2

M. Else
Given a number makes the sum and prints if it is
odd or even at the same time.

III. METHODOLOGY

For the solution of the programs we used several of


the statements used during classes like while, loop.
For. Else, if, breack, continue, goto jump, etc. We
also use the programs Dev C ++, Microsoft Visio.

IV. RESULTS

In this are placed the codes of the programs run and Pseudocode
that is what each one performs. 1. Start
2. Insert an integer number
A. If else statement. 3. Save number
In this program given an integer prints if it is 4. If the number n> 0 the number is negative, on
the contrary the number is positive
negative or positive. 5. End
#include <iostream>
using namespace std; B. If, if else and Nested ifelse.
int main()
{ In this given program any letter prints if it is vocal
int number;
cout << "Enter an integer: ";
or consonant.
cin >> number; #include <iostream>
if (number >= 0) using namespace std;
{ int main()
cout << "You entered a positive integer: {
" << number << endl; Float n1 , n2, n3;
} Cout<<enter three numbers:;
else Cin>> n1>>n2>>n3
{ If((n1>=n2)&&(n1>=n3))
cout << "You entered a negative integer: Cout<<largest number :<<n1;
" << number << endl; Else if((n21>=n1)&&(n2>=n3))
} Cout<<largest number :<<n2;
cout << "This line is always printed."; Else
return 0; Cout<<largest number: <<n3;
} return 0;
Enters. Procces. Outputs. }
Number. Condition Show numbers Enters. Procces. Outputs.
Number>=0 posive and Three Numbers . Comparison. Shows if it
negative number largest

Profesor Dr. Gabriel Romero Rodrguez


Polytechnic University of Amozoc. Bank of Programs. Programming 3

Pseudocode using namespace std;


1. Start int main()
2. Enter three number {
3. Save numbers int n, range ;
4. If the numbers n1,n2,n3 print largest cout << "Enter a positive integer: ";
cin >> n;
number , on the other hand if it is not
cout << "Enter range: ";
any of the above numbers cin >> range;
5. End
for (int i = 1; i <= range; ++i)
{
C. If, if else and Nested ifelse. cout << n << " * " << i << " = " << n * i
Given three numbers the program makes the << endl;
}
comparison of the three printing the largest number. return 0;
#include <iostream> }
using namespace std; Enters. Procces. Outputs.
int main() N. Accountant. Multiplication
{ table.
float n1, n2, n3;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if (n1 >= n2)
{
if (n1 >= n3)
cout << "Largest number: " << n1;
else
cout << "Largest number: " << n3;
}
else
{
if (n2 >= n3)
cout << "Largest number: " << n2;
else
cout << "Largest number: " << n3;
}
return 0;
}
Enters. Procces. Outputs.
N1. Condition. Show largest
N2. number.
N3.

Pseudocode
1. Start
2. Enter number
3. Save number
4. Use cycle four(MQ i=1; i<=range; ++i) to print
the result
5. End

Pseudocode
1. Start
2. Enter 3 number E. For.
3. A,B,C Save
4. If A> B entonses A> C the largest number is A In this program C ++ should be coded to work
otherwise the large number is C, if B> C correctly and Modify this program to print half
entonses B otherwise C is greater pyramid using numbers.
5. End #include <iostream>
using namespace std;
D. For Loop. int main()
Given a number the program makes the {
int i,j, rows;
multiplication table of the given number. cout << "Enter number of rows: ";
#include<iostream> cin >> rows;

Profesor Dr. Gabriel Romero Rodrguez


Polytechnic University of Amozoc. Bank of Programs. Programming 4

for(int i = 1; i <= rows; ++i) }


{ while(number != 0.0);
for(int j = 1; j <= i; ++j) cout<<"Total suma = "<<sum;
{ return 0;
cout<<i<=&j; }
} Enters. Procces. Outputs.
cout<<"\n"; Number. Sum. Result of
} addition.
return 0;
}
Enters. Procces. Outputs.
Rows. Accountant. Prints pyramid
media using
numbers.

Pseudocode
1. Start
2. Enter number interger
3. Save number
4. Performs sum process
5. Make a compareison if
6. If the result is add, to print
7. If not if will not give the result until the
negative number
8. End

G. C++ break.
In this program makes the sum of all the positive
numbers entered by the user, stopping when
inserting a negative number.
#include <iostream>
using namespace std;
int main()
{
Pseudocode float number, sum = 0.0;
1. Start // test expression is always true
2. Enter number of rows while (true)
3. Save number {
4. Use cycle while (MQ i=1; i<=N; ++i) to print cout << "Enter a number: ";
result cin >> number;
5. End if(number<0.0)
{
F. do...while Loop. goto salto;
}
In this program makes the sum of all the positive {
numbers entered by the user, stopping when sum += number;
}
inserting 0 and makes the total sum. }
#include <iostream> salto:
using namespace std; sum=sum;
int main() cout << "Suma = " << sum;
{ return 0;
float number, sum = 0.0; }
do Enters. Procces. Outputs.
{ Number. Sum. Result of
cout<<"Enter a number: "; addition.
cin>>number;
sum += number;

Profesor Dr. Gabriel Romero Rodrguez


Polytechnic University of Amozoc. Bank of Programs. Programming 5

Pseudocode
1. Start Pseudocode
2. Enter number interger 1. Start
3. Save number 2. White (MQ i<1; 1<=10; ++i)
4. Performs sum process 3. If %2=0 is true not print number
5. Make a compareison if 4. If false show number
6. If N<0.o print the result of the sum in the case 5. End
contrary not print result
7. If not if will not give the result until the
negative number I. For.
8. End
Makes the sum of an entered number (example 1 +
2 + 3 ... n) stopping when entering the number that
the user entered.
H. C++ continue. #include<iostream>
using namespace std;
Prints the sequence of 1 100 with the exception of int main()
even numbers. {
#include <iostream> int N, i, SUMA=0;
using namespace std; cout<<"Introduce un numero entero: ";
int main() cin>>N;
{ for (int i=1; i<=N; ++i)
for (int i = 1; i <= 100; ++i) {
{ SUMA = SUMA + i;
if ( i % 2 == 0 ) cout <<"\nLa suma es:"<<SUMA-
{ i<<"+"<<i<<"="<<SUMA;
continue; }
} if (N<=0)
cout << i << "\t"; {
} cout<<"El valor introducido no es
return 0; mayor a 0: ";
} }
Enters. Procces. Outputs.
i. Division. Result of the return 0;
divisin. }
Enters. Procces. Outputs.
N. Sum. Result of
i. addition.

Profesor Dr. Gabriel Romero Rodrguez


Polytechnic University of Amozoc. Bank of Programs. Programming 6

Result of
addition.

Pseudocode
1. Start
2. Enter number while (Mq i=1; i<=N; ++i)
3. For add = add=i
4. To print the result
5. The end

J. Float.
Makes the sum of the given exponents and divides
them between the same exponent, showing at the
end the total sum. Pseudocode
#include<iostream> 1. Start
using namespace std; 2. Enter number
int main() 3. Save number
{ 4. To what power do you want to raise that number
float N, E, i, power=1, division=0, sum=0; 5. Save number
cout<<"Enter a number integer: "; 6. For (i=1; i<=E; ++i)
cin>>N; 7. Operation are carried out
cout<<"To what power do you want to raise that 8. Prin result
number: "; 9. End
cin>>E;
for (int i=1; i<=E; ++i)
{ For.
power = power*N;
division = power/(i);
Given an exponent does the power dow of the
sum = sum + division; result.
cout <<"\nThe power #include<iostream>
is:"<<N<<"^"<<i<<"="<<power<<"\nThe division is: using namespace std;
"<<power<<"/"<<i<<"="<<division<<"\nThe sum is: "<<sum- int main()
division<<"+"<<division<<"="<<sum; {
} int N, E, i, power=2, sum=0;
if (E<=0) cout<<"Enter a whole number to evaluate: ";
{ cin>>N;
cout<<"The value entered is not greater than cout<<"To what power do you want to raise that
0: "; number?: ";
cin>>E;
} for (int i=1; i<=E; ++i)
{
return 0; power = power*N;
} sum = sum + power;
Enters. Procces. Outputs. cout <<"\nThe power
N. Power. Result of power. is:"<<N<<"^"<<i<<"="<<power<<"\nThe sum is: "<<sum-
E. Division. Result of power<<"+"<<power<<"="<<sum;
i. Suma. divisin. }
if (E<=0)

Profesor Dr. Gabriel Romero Rodrguez


Polytechnic University of Amozoc. Bank of Programs. Programming 7

{ sum = sum + power;


cout<<"The value entered is not greater than cout <<"\nThe power
0: "; } is:"<<N<<"^"<<i<<"="<<power<<"\nThe sum is: "<<sum-
power<<"+"<<power<<"="<<sum;
return 0; }
} if (E<=0)
Enters. Procces. Outputs. {
N. Power. Result of the cout<<"The
E. Sum. sum power. value entered is not greater than 0: ";
i. Result of }
addition.
return 0;
K. }
Enters. Procces. Outputs.
N. Power. Result of power.
E. Sum. Result of
i. addition.

Pseudocode
1. Start
2. Enter number
3. Save number Pseudocode
4. To what power do you want to sum that number 1. Start
5. Save number 2. Enter a number to evaluate
6. For ((int i=1; i<=E; ++i)) 3. Save number
7. Show the result sum of power + power 4. To what power do you want to raise that number
8. Prin result 5. Save number
9. End 6. For (i=1; i<=E; ++i)
7. Operation are carried out
8. Prin result
L. For. 9. End

Given an exponent does the sum of the result. M. Else


#include<iostream>
using namespace std;
Given a number makes the sum and prints if it is
int main() odd or even at the same time.
{ #include<iostream>
int N, E, i, power=1, sum=0; using namespace std;
cout<<"Enter a whole number to evaluate: "; int main()
cin>>N; {
cout<<"To what power do you want to raise that int N, sumpair=0, sumodd=0;
number?: "; cout<<"Enter a whole number: ";
cin>>E; cin>>N;
for (int i=1; i<=E; ++i) for (int i=1; i<=N; ++i)
{ {
power = power*N;

Profesor Dr. Gabriel Romero Rodrguez


Polytechnic University of Amozoc. Bank of Programs. Programming 8

if ( i %2 !=0 )
{
sumodd=sumodd+i;
}
else
{
sumpair=sumpair+i;
}
}
cout<<"\nThe sum of the pairs is: "<<sumpair;
cout<<"\nThe sum of the odd is: "<<sumodd;
return 0;
}
Enters. Procces. Outputs.
N. Sum. Result of
addition.

Pseudocode
1. Start
2. Enter number integer
3. Save number
4. While (MQ i=1; i<=N; ++i)
5. If is true add pair
6. If is false add sum to print the pair +i
7. To print of the add sum +i
8. End

V. CONCLUSIONES
With this program bank it is possible to say that it
is important to know the different sentences in order
to be able to solve the different problems of each
program. We require different programs such as C
++ and Visio to solve them.

Profesor Dr. Gabriel Romero Rodrguez

You might also like