Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by Kacper ( 6 years ago )
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
void underscore(char* a,size_t size)
{
for(size_t i = 0; i < size; i++)
{
//if 0-48,57-65,90-97,122-255
if(a[i]>0 && a[i]<48 || a[i]>57 && a[i]<65 || a[i]>90 && a[i]<97 || a[i]>122 && a[i]<255)
{
a[i] = 95;
}
}
}
double factorial(int n)
{
return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}
float sinapp(int x,int prec)
{
float sinv = 0;
for(int i = 0; i < 10; i++)
{
sinv = sinv + (pow((-1),i)*pow(x,(2*i+1)))/(factorial(2*i+1));
}
return sinv;
}
float cosapp(int x,int prec)
{
float cosv=0;
for(int i = 0; i < 10; i++)
{
cosv = cosv + (pow(-1,i)*pow(x,(2*(i))))/(factorial(2*i));
}
return cosv;
}
double poly(int* coef, int n, int x)
{
double result=0;
for(int i = 0;i<n;i++)
{
result = result + coef[i]*pow(x,(n-i-1));
}
return result;
}
float meanfunk(int* arr, int n)
{
float sum = 0;
for(int i = 0; i< n; i++)
{
sum = sum + arr[i];
}
return sum/n;
}
int main()
{
int size, a, b, c;
char choice=97,text[100];
srand(time(nullptr));
//std::cout<<"";
//task 0
while(choice != 'x')
{
std::cout<<"Select task:"<<std::endl
<<"1. Underscore"<<std::endl
<<"2. Sin Cos"<<std::endl
<<"3. Poly"<<std::endl
<<"4. Random mean"<<std::endl
<<"x. Exit"<<std::endl;
std::cin>>choice;
switch(choice)
{
case '1':
{
std::cout<<"Please input a text string up to 100 chars"<<std::endl;
std::cin.ignore();
std::cin.getline(text,100);
size = static_cast<size_t>(strlen(text));
underscore(text,size);
std::cout<<text<<std::endl;
break;
}
case '2':
{
std::cout<<"input the fucking variable or i'll kill your family (maybe) =)..."<<std::endl;
std::cin>>a;
std::cout<<"input the fucking precision or i'll kill your family (maybe) =)..."<<std::endl;
std::cin>>b;
std::cout<<"sin is: "<<sinapp(a,b)<<std::endl
<<"cos is: "<<cosapp(a,b)<<std::endl;
break;
}
case '3':
{
// f(x) = -3x^3 + 2x^2 â 3x + 5 // f(2) = - 17
std::cout<<"input the fucking amount of coefiaghtjyku or i'll kill your family (maybe) =)..."<<std::endl;
std::cin>>a;
std::cout<<"input the fucking x or i'll kill your family (maybe) =)..."<<std::endl;
std::cin>>b;
int coefs[a];
for (int i=0; i<a;i++)
{
std::cout<<"ILL STAB YOU IF YOU DONT INPUT COEF "<<i<<std::endl;
std::cin>>coefs[i];
}
std::cout<<poly(coefs, a, b)<<std::endl;
break;
}
case '4':
{
int b[100];
std::cout<<"<3"<<std::endl;
for(int i = 0; i< 100; i++)
{
b[i] = rand() % 100 + 50;
}
std::cout<<meanfunk(b,100)<<std::endl;
break;
}
case 'x' or 'X':
{
return 0;
break;
}
}
}
return 0;
}
Revise this Paste