Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int p1(int *x, int *y){
- return *x + *y;
- }
- // Problem 2 seems to test if more than one variable is nonzero and returns 1;
- int p2(int x, int y, int z){
- if (x == 0 && y == 0) return 0;
- if (x == 0 && z == 0) return 0;
- if (y == 0 && z == 0) return 0;
- return 1;
- }
- // Problem 3 checks to see if a given character is:
- // a lowercase letter
- // capital A
- // numbers 0-9
- int p3(char x){
- if(x == 'A') return 1;
- if(x>='0' && x <= '9') return 1;
- if(x>='a' && x <= 'z') return 1;
- return 0;
- }
- // Problem 4 computes lexicographical difference
- // between the two given strings
- int p4(char str1[], char str2[]) {
- int sum = 0;
- int count = 0;
- while(1){
- sum = str1[count] - str2[count];
- if(sum != 0)
- break;
- if(str1[count] == '\0' || str2[count] == '\0') break;
- count++;
- }
- return sum;
- }
- // Problem 5 takes an integer array as argument 1
- // an index integer for argument 2
- // and swaps the value of array[index] and array[0]
- void p5(int nums[], int len) {
- int x = 0;
- int temp = 0;
- for(x; x < len/2; x++) {
- temp = nums[x];
- nums[x] = nums[len-x-1];
- nums[len-x-1] = temp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement