Skip to content

Instantly share code, notes, and snippets.

@sp2hari
Created May 8, 2012 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sp2hari/2632756 to your computer and use it in GitHub Desktop.
Save sp2hari/2632756 to your computer and use it in GitHub Desktop.
Code snippets for Interviewstreet Sample Test
/* 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 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 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