Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. int p1(int *x, int *y){
  2. return *x + *y;
  3. }
  4.  
  5. // Problem 2 seems to test if more than one variable is nonzero and returns 1;
  6. int p2(int x, int y, int z){
  7. if (x == 0 && y == 0) return 0;
  8. if (x == 0 && z == 0) return 0;
  9. if (y == 0 && z == 0) return 0;
  10. return 1;
  11. }
  12.  
  13. // Problem 3 checks to see if a given character is:
  14. // a lowercase letter
  15. // capital A
  16. // numbers 0-9
  17. int p3(char x){
  18. if(x == 'A') return 1;
  19. if(x>='0' && x <= '9') return 1;
  20. if(x>='a' && x <= 'z') return 1;
  21. return 0;
  22. }
  23.  
  24. // Problem 4 computes lexicographical difference
  25. // between the two given strings
  26. int p4(char str1[], char str2[]) {
  27. int sum = 0;
  28. int count = 0;
  29. while(1){
  30. sum = str1[count] - str2[count];
  31. if(sum != 0)
  32. break;
  33. if(str1[count] == '\0' || str2[count] == '\0') break;
  34. count++;
  35. }
  36. return sum;
  37. }
  38.  
  39. // Problem 5 takes an integer array as argument 1
  40. // an index integer for argument 2
  41. // and swaps the value of array[index] and array[0]
  42. void p5(int nums[], int len) {
  43. int x = 0;
  44. int temp = 0;
  45. for(x; x < len/2; x++) {
  46. temp = nums[x];
  47. nums[x] = nums[len-x-1];
  48. nums[len-x-1] = temp;
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement