using functional decomposition, write a program that produces the foll

Using functional decomposition, write a program that produces the foll

Page 1 of 1

2 Replies - 2183 Views - Last Post: 04 May 2008 - 07:53 AM Rate Topic: -----

#1 princeofhere  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 30-April 08

using functional decomposition, write a program that produces the foll

Posted 04 May 2008 - 07:34 AM

Using functional decomposition, write a program that produces the following
1
1 2
1 2 3
1 2 3 4
.
.
1 2 3 4 5 .. 20
for a user input of 20, or similar output for any other input.
Print out the output you get for the following inputs, 5, 10, 15 and turn it in.





#include<iostream>
#include<string>
using namespace std;

int x;
int main()
{
cin>>x;
if (x==5)
cout<<" 1 "<<endl<<" 1 2 "<<endl<<" 1 2 3 "<<endl<<" 1 2 3 4"<<endl<<" 1 2 3 4 5 "<<endl;
else
if(x==10)
cout<<" 1 "<<endl<<" 1 2 "<<endl<<" 1 2 3 "<<endl<<" 1 2 3 4"<<endl<<" 1 2 3 4 5 "<<endl<<" 1 2 3 4 5 6"<<endl<<" 1 2 3 4 5 6 7"<<endl<<" 1 2 3 4 5 6 7 8"<<endl<<" 1 2 3 4 5 6 7 8 9"<<endl<<" 1 2 3 4 5 6 7 8 9 10"<<endl;
else if (x==15)
cout<<" 1 "<<endl<<" 1 2 "<<endl<<" 1 2 3 "<<endl<<" 1 2 3 4"<<endl<<" 1 2 3 4 5 "<<endl<<" 1 2 3 4 5 6"<<endl<<" 1 2 3 4 5 6 7"<<endl<<" 1 2 3 4 5 6 7 8"<<endl<<" 1 2 3 4 5 6 7 8 9"<<endl<<" 1 2 3 4 5 6 7 8 9 10"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12 13"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12 13 14"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"<<endl;
else if (x==20)
cout<<" 1 "<<endl<<" 1 2 "<<endl<<" 1 2 3 "<<endl<<" 1 2 3 4"<<endl<<" 1 2 3 4 5 "<<endl<<" 1 2 3 4 5 6"<<endl<<" 1 2 3 4 5 6 7"<<endl<<" 1 2 3 4 5 6 7 8"<<endl<<" 1 2 3 4 5 6 7 8 9"<<endl<<" 1 2 3 4 5 6 7 8 9 10"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12 13"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12 13 14"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 "<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 "<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19"<<endl<<" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 "<<endl;



return 0;
}


is that the right code or shall i write it as while , if yes how please

Is This A Good Question/Topic? 0
  • +

Replies To: using functional decomposition, write a program that produces the foll

#2 Cerolobo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 450
  • Joined: 05-April 08

Re: using functional decomposition, write a program that produces the foll

Posted 04 May 2008 - 07:38 AM

It will be a lot shorter and cleaner to use a loop.

Here is a hint, you can pass numbers to cout.

cout << 12345 << "\n";



will produce
12345
Was This Post Helpful? 0
  • +
  • -

#3 princeofhere  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 30-April 08

Re: using functional decomposition, write a program that produces the foll

Posted 04 May 2008 - 07:53 AM

View PostCerolobo, on 4 May, 2008 - 07:38 AM, said:

It will be a lot shorter and cleaner to use a loop.

Here is a hint, you can pass numbers to cout.

cout << 12345 << "\n";



will produce
12345


can u be more clear plz
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1