Algorithm in C++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2007
Posts: 21
Reputation: faisaly is an unknown quantity at this point 
Solved Threads: 0
faisaly faisaly is offline Offline
Newbie Poster

Algorithm in C++

 
0
  #1
Nov 10th, 2008
Considering the given code as an algorithm calculate the time complexity of this code.

#include<iostream>
#include<stdlib.h>
using namespace std;

int main(){
int i, j, n;
for(i=0;i<n; i++){

for(j=0; j<n; j++){
cout<<"my time complexity is = "<<i*j<<endl;
}
cout<<"complexity is increasing"<<j<<endl;
}
system("pause");
return 0;
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Algorithm in C++

 
0
  #2
Nov 10th, 2008
Well, you demonstrate absolutely senseless code (n is not initialized).
And what's your question?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Algorithm in C++

 
0
  #3
Nov 10th, 2008
Originally Posted by faisaly View Post
Considering the given code as an algorithm calculate the time complexity of this code.

#include<iostream>
#include<stdlib.h>
using namespace std;

int main(){
int i, j, n;
for(i=0;i<n; i++){

for(j=0; j<n; j++){
cout<<"my time complexity is = "<<i*j<<endl;
}
cout<<"complexity is increasing"<<j<<endl;
}
system("pause");
return 0;
}
Code tags please [code=cplusplus][/]code]. Also if our asking what the time complexity is. Why don't you consider showing us what you understand before we just tell you.

Also it should be cstdlib, since this is cplusplus

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4.  
  5. int main(){
  6. int i, j, n;
  7. for(i=0;i<n; i++){
  8.  
  9. for(j=0; j<n; j++){
  10. cout<<"my time complexity is = "<<i*j<<endl;
  11. }
  12. cout<<"complexity is increasing"<<j<<endl;
  13. }
  14. system("pause");
  15. return 0;
  16. }

But indeed agreein with ArkM what is n?

Chris
Last edited by Freaky_Chris; Nov 10th, 2008 at 4:40 am.
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC