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;
}

Edited 3 Years Ago by happygeek: fixed formatting

Well, you demonstrate absolutely senseless code (n is not initialized).
And what's your question?

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

[/[TEX]][/TEX]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

[CODE=cplusplus]#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

This article has been dead for over six months. Start a new discussion instead.