Commit 144563ff authored by Artak Yenokyan's avatar Artak Yenokyan

Merge branch 'Branch4.35' into 'master'

michael.davityan:exercise_04_35v9

See merge request bpcarm/trainings2017!1358
parents 8491c6a0 6059a3b3
progname=exercise_04_35
CC=g++
CFLAGS=-Wall -Wextra -Werror -g3
all: test1 test2 test3 test4 test5 test6
debug/$(progname): debug/$(progname).o
$(CC) $(CFLAGS) $< -o $@
debug/%.o: debug/%.s
$(CC) -c $(CFLAGS) $< -o $@
debug/%.s: debug/%.ii
$(CC) -S $(CFLAGS) $< -o $@
debug/%.ii: %.cpp | debug
$(CC) -E $(CFLAGS) $< -o $@
debug:
mkdir -p debug
clean:
rm -r debug Tests/*.out
test%: debug/$(progname)
@./debug/$(progname) < Tests/$@.in > Tests/$@.out 2>&1 || echo "$@ is executing..."
@diff Tests/$@.out Tests/$@.expected && echo PASSED || echo FAILED
.PRECIOUS: debug/%.ii debug/%.s
.SECONDARY: debug/%.ii debug/%.s
This is the (a) point of lesson....
The factorial is 0!=1
------------------------------------------------------------------------------------------------------
This is the (b) & (c) point of lesson....
e = 1
e to the power of 0 will be: 1
======================================================================================================
This is the (a) point of lesson....
The factorial is 1!=1
------------------------------------------------------------------------------------------------------
This is the (b) & (c) point of lesson....
e = 1
e to the power of 0 will be: 1
======================================================================================================
This is the (a) point of lesson....
The factorial is 5!=120
------------------------------------------------------------------------------------------------------
This is the (b) & (c) point of lesson....
e = 2.66667
e to the power of 2 will be: 6.33333
======================================================================================================
This is the (a) point of lesson....
The factorial is 9!=362880
------------------------------------------------------------------------------------------------------
This is the (b) & (c) point of lesson....
e = 2.66667
e to the power of -2 will be: -0.333333
======================================================================================================
This is the (a) point of lesson....
Error 1: Input number should be positive.
This is the (a) point of lesson....
The factorial is 7!=5040
------------------------------------------------------------------------------------------------------
This is the (b) & (c) point of lesson....
Error 1: accuracy value must be possitive.
#include <iostream>
#include <unistd.h>
int
main()
{
/// This is the (a) point of lesson....
std::cout << "This is the (a) point of lesson....\n";
if (::isatty(STDIN_FILENO)) {
std::cout << "Input number to calculate it's factorial: ";
}
int number;
std::cin >> number;
if (number < 0) {
std::cout << "Error 1: Input number should be positive. " << std::endl;
return 1;
}
std::cout << "The factorial is " << number << "!=";
int factorialOfNumber = 1;
while (number > 1) {
factorialOfNumber *= number;
--number;
}
std::cout << factorialOfNumber << std::endl;
std::cout << "------------------------------------------------------------------------------------------------------\n";
/// This is the (b) & (c) point of lesson....
std::cout << "This is the (b) & (c) point of lesson....\n";
if (::isatty(STDIN_FILENO)) {
std::cout << "Input the power of e: ";
}
int power;
std::cin >> power;
if (::isatty(STDIN_FILENO)) {
std::cout << "Input the accuracy of the series e: ";
}
int accuracy;
std::cin >> accuracy;
if (accuracy < 0) {
std::cout << "Error 1: accuracy value must be possitive." << std::endl;
return 1;
}
int denominator = 1;
double denominatorFactorial = 1.0;
double eConstant = 1.0;
double powerOfE = 1.0;
int numerator = 1;
while (denominator <= accuracy) {
numerator *= power;
denominatorFactorial *= denominator;
eConstant += 1.0 / denominatorFactorial;
powerOfE += numerator / denominatorFactorial;
++denominator;
}
std::cout << "e = " << eConstant << std::endl;
std::cout << "e to the power of " << power << " will be: "<< powerOfE << std::endl;
std::cout << "======================================================================================================" << std::endl;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment