Advertisement
Yanislav29

Untitled

Nov 26th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. // zadacha 1
  2. // тук програмата извежда броя на чифрите на въведеното число.
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8. int main()
  9. {
  10.  
  11. int num;
  12. int digit = 0 ;
  13. cout << "Enter number:" << endl;
  14. cin >> num;
  15.  
  16. do
  17. {
  18. num = num / 10;
  19. digit++;
  20. } while (num != 0);
  21. cout << "Number of digits in the given integer is: " << digit;
  22.  
  23.  
  24. }
  25. задача 2:
  26. // zadacha 2
  27. // тук програмата извежда сбора на числата на въведеното число.
  28.  
  29. #include "pch.h"
  30. #include <iostream>
  31.  
  32. using namespace std;
  33. int main()
  34. {
  35.  
  36. int num;
  37. int digit = 0 ;
  38. cout << "Enter number:" << endl;
  39. cin >> num;
  40.  
  41. while (num != 0) {
  42.  
  43. digit = digit + num % 10;
  44. num = num / 10;
  45. }
  46.  
  47. cout << "Number of digits in the given integer is: " << digit;
  48.  
  49.  
  50. }
  51. задача 3:
  52. // zadacha 3
  53. //
  54.  
  55. #include "pch.h"
  56. #include <iostream>
  57.  
  58. using namespace std;
  59. int main()
  60. {
  61. int a;
  62. int num;
  63. int c = 0;
  64. cout << "Enter number:" << endl;
  65. cin >> num;
  66.  
  67. while (num != 0) {
  68.  
  69. a = num % 10;
  70. c = c * 10 + a;
  71. num = num / 10;
  72. }
  73.  
  74. cout << "Number of digits in the given integer is: " << c;
  75.  
  76.  
  77. }
  78. задача 4 :
  79. // zad 4 lab.cpp : This file contains the 'main' function. Program execution begins and ends there.
  80. //
  81.  
  82. #include "pch.h"
  83. #include <iostream>
  84. #include <cmath>
  85. using namespace std;
  86.  
  87.  
  88.  
  89. int main()
  90. {
  91. int givenNum;
  92. cout << "Enter number:";
  93. cin >> givenNum;
  94. int current;
  95. int currentcounter = 0;
  96. int numbers[10] = { 0,1,2,3,4,5,6,7,8,9 };
  97.  
  98. for (int i = 0; i < 10; i++) {
  99.  
  100. while (givenNum > 0) {
  101.  
  102. if ((givenNum % 10) == numbers[i]) {
  103.  
  104. currentcounter++;
  105. }
  106. givenNum = givenNum / 10;
  107. }
  108. cout << numbers[i] << "/" << currentcounter << endl;
  109. currentcounter = 0;
  110. }
  111.  
  112. return 0;
  113. }
  114.  
  115.  
  116. задача 5 :
  117. // Dom rabota zad 5 lekciya .cpp : This file contains the 'main' function. Program execution begins and ends there.
  118. //
  119.  
  120. #include "pch.h"
  121. #include <iostream>
  122. #include <string>
  123. #include <sstream>
  124. using namespace std;
  125.  
  126. int main()
  127. {
  128. char symbol;
  129. int rowcount;
  130. int space;
  131. cout << "Enter a symbol:";
  132. cin >> symbol;
  133.  
  134. cout << "Enter row number:" << endl;
  135. cin >> rowcount;
  136.  
  137. for (size_t i = 0; i < rowcount; i++) {
  138.  
  139. for (space = 1; space <= rowcount - i; ++space) {
  140. cout << " ";
  141. }
  142. for (int j = 0; j < 1; j++) {
  143. cout << symbol;
  144. cout << " ";
  145. }
  146. cout << "\n";
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement