Code snippets for Interviewstreet Sample Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is the correct working solution */ | |
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, sum = 0; | |
cin >> n; | |
for (int i=0; i<=n; i++) { | |
sum += i; | |
} | |
cout << sum << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This code is logically correct, but has output format error */ | |
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, sum = 0; | |
cout << "Enter the number N" << endl; // THIS LINE SHOULD NOT BE PRESENT. DON'T PRINT ANYTHING EXTRA | |
cin >> n; | |
for (int i=0; i<=n; i++) { | |
sum += i; | |
} | |
cout << sum << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This code is logically correct, but has output format ERROR */ | |
/* This code is logically correct, but has output format error */ | |
#include <iostream> | |
using namespace std; | |
int main() { | |
int n, sum = 0; | |
cin >> n; | |
for (int i=0; i<=n; i++) { | |
sum += i; | |
} | |
cout << "The result is " << endl; // THIS LINE SHOULD NOT BE PRESENT. DON'T PRINT ANYTHING EXTRA | |
cout << sum << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment