Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions