-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <iostream> | ||
|
||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int a[] = {1, 2, 3, 4, 5}; | ||
int b[5]; | ||
for (auto c : b){ | ||
cout << c << 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <iostream> | ||
|
||
int main(){ | ||
int values = 0, sum = 0; | ||
std::cin >> values; | ||
while (std::cin){ | ||
sum += values; | ||
} | ||
std::cout << sum << std::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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <iostream> | ||
|
||
int main(){ | ||
int sum = 0; | ||
for (int val = 1; val <= 10; ++val){ | ||
sum += val; | ||
} | ||
std::cout << sum << std::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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int factorial(int n){ | ||
if (n == 0){ | ||
return 1; | ||
} | ||
|
||
else{ | ||
int product = 1; | ||
for (int i = n; i != 0; --i){ | ||
product *= i; | ||
} | ||
return product; | ||
} | ||
} | ||
|
||
|
||
int main(){ | ||
int n; | ||
while (cin >> n){ | ||
auto nFactorial = factorial(n); | ||
cout << nFactorial << ' '; | ||
} | ||
cout << 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <iostream> | ||
int main() | ||
{ | ||
std::cout << "Hello, world!" << std::endl; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <iostream> | ||
|
||
int main(){ | ||
int currVal = 0, val = 0; | ||
if (std::cin >> currVal) { | ||
int cnt = 1; | ||
while (std::cin >> val) { | ||
if (val == currVal) { | ||
++cnt; | ||
} | ||
else { | ||
std::cout << currVal << " occurs " << cnt | ||
<< " times" << std::endl; | ||
currVal = val; | ||
cnt = 1; | ||
} | ||
} | ||
std::cout << currVal << " occurs " << cnt | ||
<< " times" << std::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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
vector<int> ivec{1, 2, 3, 4, 5}; | ||
for (auto b = ivec.begin(); b != ivec.end(); ++b){ | ||
cout << *b << endl; // Bruk *-operatoren for å hente ut elementer | ||
} | ||
for (auto b = ivec.begin(); b != ivec.end(); ++b){ | ||
*b = 0; | ||
} | ||
for (auto b = ivec.begin(); b != ivec.end(); ++b){ | ||
cout << *b << 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int ival = 42; | ||
int *p = &ival; // p is a pointer and holds the address of ival by using the | ||
// &-operator | ||
|
||
cout << *p << endl; // Yields the object which p points to by using the | ||
// *-operator (prints 42) | ||
|
||
cout << p << endl; // Yields the address of ival | ||
|
||
*p = 0; // We can assign a new value to ival by using *p | ||
|
||
cout << ival << endl; // prints 0 | ||
|
||
int jval = 69; | ||
|
||
p = &jval; // p is now a pointer to jval | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
string str = "some string"; | ||
for (auto c : str){ | ||
cout << c << 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
#include <iostream> | ||
int main() | ||
{ | ||
std::cout << "Enter two numbers:" << std::endl; | ||
int v1 = 0, v2 = 0; | ||
std::cin >> v1 >> v2; | ||
std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1 + v2 << std::endl; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
string inputString, concatString; | ||
while (getline(cin, inputString)){ | ||
concatString += (inputString + ' '); | ||
} | ||
cout << concatString << endl; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
#include <cmath> | ||
#include <cctype> | ||
#include <array> | ||
#include <cstdlib> | ||
#include <cstdio> | ||
using namespace std; | ||
|
||
|
||
int main() | ||
{ | ||
const int n = 5; | ||
double b[n] = {}; | ||
|
||
n = 2; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
using namespace std; | ||
|
||
int main(){ | ||
vector<int> v1, v2; | ||
v1 = {1, 2, 3}; | ||
v2 = {1, 2, 3}; | ||
bool trueOrFalse = v1 == v2; | ||
cout << trueOrFalse << 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <iostream> | ||
|
||
int main(){ | ||
int sum = 0, val = 1; | ||
while (val <= 10) { | ||
sum += val; | ||
++val; | ||
} | ||
std::cout << "Sum of 1 to 10 inclusive is " << sum << std::endl; | ||
return 0; | ||
} |