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

Edited by happygeek: fixed formatting

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Freaky_Chris
0

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

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

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.