Merge branch 'scheduling' of https://github.com/Pratyush219/C-Plus-Plus into scheduling

This commit is contained in:
Pratyush219
2021-10-14 08:18:02 +05:30
2 changed files with 36 additions and 17 deletions

View File

@@ -8,15 +8,15 @@
* @author [Pratyush Vatsa](https://github.com/Pratyush219) * @author [Pratyush Vatsa](https://github.com/Pratyush219)
*/ */
#include <iostream> /// for IO operations
#include <queue> /// for std::priority_queue
#include <unordered_set> /// for std::unordered_set
#include <vector> /// for std::vector
#include <algorithm> /// for sorting #include <algorithm> /// for sorting
#include <cassert> /// for assert #include <cassert> /// for assert
#include <cstdlib> /// random number generation #include <cstdlib> /// random number generation
#include <ctime> /// for time #include <ctime> /// for time
#include <iomanip> /// for formatting the output #include <iomanip> /// for formatting the output
#include <iostream> /// for IO operations
#include <queue> /// for std::priority_queue
#include <unordered_set> /// for std::unordered_set
#include <vector> /// for std::vector
using std::cin; using std::cin;
using std::cout; using std::cout;
@@ -271,7 +271,8 @@ void test() {
readyQueue.addProcess(get<0>(input[i]), get<1>(input[i]), readyQueue.addProcess(get<0>(input[i]), get<1>(input[i]),
get<2>(input[i])); get<2>(input[i]));
} }
vector<tuple<uint32_t, uint32_t, uint32_t, double, double, double>> res = get_final_status<uint32_t, uint32_t, uint32_t>(input); vector<tuple<uint32_t, uint32_t, uint32_t, double, double, double>>
res = get_final_status<uint32_t, uint32_t, uint32_t>(input);
assert(res == readyQueue.scheduleForFcfs()); assert(res == readyQueue.scheduleForFcfs());
// readyQueue.printResult(); // readyQueue.printResult();
} }

View File

@@ -1,21 +1,39 @@
// Program to check whether a number is an armstrong number or not // Program to check whether a number is an armstrong number or not
#include <cmath>
#include <iostream> #include <iostream>
using std::cin; using std::cin;
using std::cout; using std::cout;
int main() { int main() {
int n, k, d, s = 0; int n = 0, temp = 0, rem = 0, count = 0, sum = 0;
cout << "Enter a number:"; cout << "Enter a number: ";
cin >> n; cin >> n;
k = n;
while (k != 0) { temp = n;
d = k % 10;
s += d * d * d; /* First Count the number of digits
k /= 10; in the given number */
while (temp != 0) {
temp /= 10;
count++;
} }
if (s == n)
cout << n << "is an armstrong number"; /* Calaculation for checking of armstrongs number i.e.
else in a n digit number sum of the digits raised to a power of n
cout << n << "is not an armstrong number"; is equal to the original number */
temp = n;
while (temp != 0) {
rem = temp % 10;
sum += static_cast<int>(pow(rem, count));
temp /= 10;
}
if (sum == n) {
cout << n << " is an armstrong number";
} else {
cout << n << " is not an armstrong number";
}
return 0;
} }