Advertisement
LikeRampage

C++ Multithreading code with run two threads one thread 1.Calculate C++ Program to Add Two Numbers.

Apr 27th, 2024
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. cpp
  2. #include <iostream>
  3. #include <thread>
  4.  
  5. void addNumbers(int a, int b) {
  6.     int sum = a + b;
  7.     std::cout << "Sum of " << a << " and " << b << " is: " << sum << std::endl;
  8. }
  9.  
  10. void findQuotientAndRemainder(int dividend, int divisor) {
  11.     int quotient = dividend / divisor;
  12.     int remainder = dividend % divisor;
  13.     std::cout << "Quotient of " << dividend << " divided by " << divisor << " is: " << quotient << std::endl;
  14.     std::cout << "Remainder of " << dividend << " divided by " << divisor << " is: " << remainder << std::endl;
  15. }
  16.  
  17. int main() {
  18.     int num1 = 10;
  19.     int num2 = 5;
  20.     int dividend = 20;
  21.     int divisor = 3;
  22.  
  23.     std::thread thread1(addNumbers, num1, num2);
  24.     std::thread thread2(findQuotientAndRemainder, dividend, divisor);
  25.  
  26.     thread1.join();
  27.     thread2.join();
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement