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

Graph

The document contains C++ code that defines functions to calculate and plot the values of a function f(x)=x^n + x^(n-1). It takes user input for values of x and n. It allocates a 2D array to store the plotted values, with the first dimension size determined by the function value and the second by x. It calculates the function values and marks the corresponding indices in the 2D array with a character. It then prints the plotted values.

Uploaded by

Raawna Boy
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Graph

The document contains C++ code that defines functions to calculate and plot the values of a function f(x)=x^n + x^(n-1). It takes user input for values of x and n. It allocates a 2D array to store the plotted values, with the first dimension size determined by the function value and the second by x. It calculates the function values and marks the corresponding indices in the 2D array with a character. It then prints the plotted values.

Uploaded by

Raawna Boy
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 10

#include <iostream>

#include <cmath>
#include <cstring>
using namespace std;
double ans(int* x, int* n);
void solution(int* x, int* nth, char arr[][100]);
int main()
{

char array[100][100]{};
cout << "Enter the value of x for f(x)= x^n +x^n-1 ";
int num1;
cin >> num1;
cout << "Enter the value of n for f(x)= x^n +x^n-1 ";
int num2;
cin >> num2;

solution(&num1, &num2, array);

return 0;
}
double ans(int* x, int* n )
{
return pow(*x, *n) + pow(*x, *n - 1);
}
void solution(int* x, int* nth, char arr[][100])
{
int answer;
int y=ans(x,nth);
for (int i = 0; i < *x; i++)
{
answer = ans(&i, nth);
arr[i][answer]='.';
}
cout << ' ';
for (int i = 0; i <= *x; i++)
{
cout << i << ' ';
}
for (int i = 0; i <= y; i++)
{
cout << i << endl;
}

for (int i = 0; i < 100; i++)


{

for (int j = 0; j < 100; j++)


{
if (j != y)
{
cout << arr[i][j] << endl;
}
else { break; }
}
}

#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int ans(int* x, int* n);
void solution(int* x, int* nth, char **box);
int main()
{

char **array=NULL;
cout << "Enter the value of x for f(x)= x^n +x^n-1 ";
int num1;
cin >> num1;
cout << "Enter the value of n for f(x)= x^n +x^n-1 ";
int num2;
cin >> num2;

solution(&num1, &num2, array);

delete[]array;
return 0;
}
int ans(int* x, int* n)
{
return pow(*x, *n) + pow(*x, *n - 1);
}
void solution(int* x, int* nth, char** box)
{

int y = ans(x, nth);


box = new char* [y];

for (int i = 0; i < y; i++)


{
char *box = new char[*x];
}

int answer;

/*for (int j = 0; j < *x; j++)


{
answer = ans(&j, nth);
*(*(box + answer) + j) = '.';
}*/

for (int i = 0; i < *x; i++)


{
for (int j = 0; j < y; j++)
{
*(*(box + i) + j) = 'f';
}

for (int i = 0; i < *x; i++)


{
for (int j = 0; j < y; j++)

{
cout << *(*(box + i) + j) <<' ';
}

}
//*cout << ' ';
//for (int i = 0; i <= *x; i++)
//{
// cout << i << ' ';
//}
//for (int i = 0; i <= y; i++)
//{
// cout << i << endl;
//}*/

//for (int i = 0; i < 100; i++)


//{

// for (int j = 0; j < 100; j++)


// {
// if (j != y)
// {
// cout << arr[i][j] << endl;
// }
// else { break; }
// }

#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int ans(int* x, int* n);
void solution(int* x, int* nth, char **box);
int main()
{

char **array=NULL;
cout << "Enter the value of x for f(x)= x^n +x^n-1 ";
int num1;
cin >> num1;
cout << "Enter the value of n for f(x)= x^n +x^n-1 ";
int num2;
cin >> num2;
solution(&num1, &num2, array);

delete[]array;
return 0;
}
int ans(int* x, int* n)
{
return pow(*x, *n) + pow(*x, *n - 1);
}
void solution(int* x, int* nth, char** box)
{
int xaxis = *x;
int yaxis= ans(x, nth);
box = new char* [yaxis];

for (int i = 0; i < yaxis; i++)


{
box[i] = new char[xaxis];
}

int answer;

for (int j = 0; j < xaxis; j++)


{
answer = ans(&j, nth);
*(*(box + answer) + j) = '.';
}

/*for (int i = 0; i < yaxis; i++)


{
for (int j = 0; j < xaxis; j++)

{
*(*(box + i) + j) = 'f';
}

}*/

/*for (int i = 0; i < xaxis; i++)


{

for (int i = 0; i < yaxis; i++)


{
cout << i << ' ';
}

for (int i = 0; i < yaxis; i++)


{
for (int j = 0; j < xaxis; j++)

{
cout <<' ' << *(*(box + i) + j) ;
}
cout << endl;

}*/

for (int i = 0; i < xaxis; i++)


{
int answer = ans(&i, nth);
box[answer][i] = 'x'; // Use 'x' instead of '.' to mark the
specific point
}

//for (int i = 0; i < yaxis; i++) {


// for (int j = 0; j < xaxis; j++) {
// if (box[i][j] == 'x') {
// cout << box[i][j] << ' '; // Print 'x' for specific
points
// }
// else {
// cout << ans(&j, nth) << ' '; // Print the
corresponding number
// }
// }
// cout << endl;
//}
//*cout << ' ';
//for (int i = 0; i <= *x; i++)
//{
// cout << i << ' ';
//}
//for (int i = 0; i <= y; i++)
//{
// cout << i << endl;
//}*/

//for (int i = 0; i < 100; i++)


//{

// for (int j = 0; j < 100; j++)


// {
// if (j != y)
// {
// cout << arr[i][j] << endl;
// }
// else { break; }
// }

#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int ans(int* x, int* n);
void solution(int* x, int* nth, char **box);
int main()
{

char **array=NULL;
cout << "Enter the value of x for f(x)= x^n +x^n-1 ";
int num1;
cin >> num1;
cout << "Enter the value of n for f(x)= x^n +x^n-1 ";
int num2;
cin >> num2;

solution(&num1, &num2, array);

delete[]array;
return 0;
}
int ans(int* x, int* n)
{
return pow(*x, *n) + pow(*x, *n - 1);
}
void solution(int* x, int* nth, char** box)
{
int xaxis = *x;
int yaxis= ans(x, nth);
box = new char* [yaxis];

for (int i = 0; i < yaxis; i++)


{
box[i] = new char[xaxis];
}

int answer;

for (int j = 0; j < xaxis; j++)


{
answer = ans(&j, nth);
*(*(box + answer) + j) = '.';
}

/*for (int i = 0; i < yaxis; i++)


{
for (int j = 0; j < xaxis; j++)

{
*(*(box + i) + j) = 'f';
}

}*/

/*for (int i = 0; i < xaxis; i++)


{

for (int i = 0; i < yaxis; i++)


{
cout << i << ' ';
}

for (int i = 0; i < yaxis; i++)


{
for (int j = 0; j < xaxis; j++)

{
cout <<' ' << *(*(box + i) + j) ;
}
cout << endl;

}*/

for (int i = 0; i < xaxis; i++)


{
int answer = ans(&i, nth);
box[answer][i] = 'x'; // Use 'x' instead of '.' to mark the
specific point
}

//for (int i = 0; i < yaxis; i++) {


// for (int j = 0; j < xaxis; j++) {
// if (box[i][j] == 'x') {
// cout << box[i][j] << ' '; // Print 'x' for specific
points
// }
// else {
// cout << ans(&j, nth) << ' '; // Print the
corresponding number
// }
// }
// cout << endl;
//}
//*cout << ' ';
//for (int i = 0; i <= *x; i++)
//{
// cout << i << ' ';
//}
//for (int i = 0; i <= y; i++)
//{
// cout << i << endl;
//}*/

//for (int i = 0; i < 100; i++)


//{

// for (int j = 0; j < 100; j++)


// {
// if (j != y)
// {
// cout << arr[i][j] << endl;
// }
// else { break; }
// }
}

#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int ans(int* x, int* n);
void solution(int* x, int* nth, char **box);
int main()
{

char **array=NULL;
cout << "Enter the value of x for f(x)= x^n +x^n-1 ";
int num1;
cin >> num1;
cout << "Enter the value of n for f(x)= x^n +x^n-1 ";
int num2;
cin >> num2;

solution(&num1, &num2, array);

delete[]array;
return 0;
}
int ans(int* x, int* n)
{
return pow(*x, *n) + pow(*x, *n - 1);
}
void solution(int* x, int* nth, char** box)
{
int xaxis = *x;
int yaxis= ans(x, nth);
box = new char* [yaxis];

for (int i = 0; i < yaxis; i++)


{
box[i] = new char[xaxis];
}

int answer;

for (int j = 0; j < xaxis; j++)


{
answer = ans(&j, nth);
*(*(box + answer) + j) = '.';
}

/*for (int i = 0; i < yaxis; i++)


{
for (int j = 0; j < xaxis; j++)

{
*(*(box + i) + j) = 'f';
}

}*/

/*for (int i = 0; i < xaxis; i++)


{

for (int i = 0; i < yaxis; i++)


{
cout << i << ' ';
}

for (int i = 0; i < yaxis; i++)


{
for (int j = 0; j < xaxis; j++)

{
cout <<' ' << *(*(box + i) + j) ;
}
cout << endl;

}*/

for (int i = 0; i < xaxis; i++)


{
int answer = ans(&i, nth);
box[answer][i] = 'x'; // Use 'x' instead of '.' to mark the
specific point
}

//for (int i = 0; i < yaxis; i++) {


// for (int j = 0; j < xaxis; j++) {
// if (box[i][j] == 'x') {
// cout << box[i][j] << ' '; // Print 'x' for specific
points
// }
// else {
// cout << ans(&j, nth) << ' '; // Print the
corresponding number
// }
// }
// cout << endl;
//}
//*cout << ' ';
//for (int i = 0; i <= *x; i++)
//{
// cout << i << ' ';
//}
//for (int i = 0; i <= y; i++)
//{
// cout << i << endl;
//}*/

//for (int i = 0; i < 100; i++)


//{
// for (int j = 0; j < 100; j++)
// {
// if (j != y)
// {
// cout << arr[i][j] << endl;
// }
// else { break; }
// }

You might also like