Question: Need help Rewrite problem #4 with a static input of n=99 (written into the code), the output should be written to a file named: problem4fileoutput.txt

Need help

Rewrite problem #4 with a static input of n=99 (written into the code), the output should be written to a file named: problem4fileoutput.txt , and do not use the same type of loops as in problem #4. The file should be included as a separate attachment when uploading your work.

#include

using namespace std;

int fact(int n){

//function for get factorial

if(n==1) return 1;

else return n*fact(n-1);

}

int sum(int n){

// function for get sum of n natural number

if(n==1) return 1;

else return n+sum(n-1);

}

// main start from here

int main(){

int no; // value will be taken by user

cout<<"Enter value of n:";

cin>>no;

int rmd=no%3;// remainder of user value

no= no-rmd;// number ,divisible by 3

int i;

for(i=1;i<=no;){ // this for loop will print all result till no is divisible by 3

// rest of result will be printed after this for loop

cout<<"Number (n)\t\t";

cout<

cout<

cout<

cout<<" ";// new line

cout<<"sum of (n)\t\t";

cout<

cout<

cout<

cout<<" "; //new line

cout<<"factorial of (n)\t";

cout<

cout<

cout<

cout<<" "; //2 new lines

}

if(rmd==0) {return 0;}

//if remainder is 0 code will stop here

//other wise it print rest of result

cout<<"Number (n)\t\t";

for(int j=1;j<=rmd;j++){

cout<

}

cout<<" ";

cout<<"sum of (n)\t\t";

for(int j=1;j<=rmd;j++){

cout<

}

cout<<" ";

cout<<"factorial of (n)\t";

for(int j=1;j<=rmd;j++){

cout<

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!