Guest User

Untitled

a guest
Jan 2nd, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. // strlen1, strcpy1
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. #define UINT unsigned int
  7.  
  8. UINT strlen1(const char str[]) {
  9.     int len = 0;
  10.     while (str[len] != '\0') {
  11.         len++;
  12.     }
  13.     return len;
  14. }
  15.  
  16. void strcpy1(char dest[], char src[]) {
  17.     int i = 0;
  18.     while (src[i] != '\0') {
  19.         dest[i] = src[i];
  20.         i++;
  21.     }
  22.     dest[i] = '\0';
  23. }
  24.  
  25. int main(int argc, char **argv) {
  26.     cout << "Input: "<< argv[1] << endl;
  27.     cout << "Length: "<< strlen1(argv[1]) << endl;
  28.     char inputCopy[25];
  29.     strcpy1(inputCopy, argv[1]);
  30.     cout << "Copy: "<< inputCopy << endl;
  31.     return 0;
  32. }
  33.  
  34.  
  35. // факторіал
  36. #include <iostream>
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39.  
  40. using namespace std;
  41.  
  42. long long factorial(int n) {
  43.     if (n == 0) {
  44.         return 1;
  45.     } else {
  46.         return n * factorial(n - 1);
  47.     }
  48. }
  49.  
  50. int main(int argc, char **argv) {
  51.     int n = atoi(argv[1]);
  52.     cout << "Factorial of "<< n << ": " << factorial(n) << endl;
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment