| | |
Algorithm in C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2007
Posts: 21
Reputation:
Solved Threads: 0
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;
}
#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;
}
•
•
•
•
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;
}
Also it should be cstdlib, since this is cplusplus
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<cstdlib> 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; }
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
![]() |
Similar Threads
- Help with LR parser algorithm (Java)
- round robin algorithm (Computer Science)
- Round Robin Algorithm Simulation (C++)
- Eigenface Algorithm (Computer Science)
- Algorithm for checking contiguous blocks (C)
Other Threads in the C++ Forum
- Previous Thread: How can I register COM Compnent in VC++
- Next Thread: Flexie Programming Assignment
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






