Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int operation(int *arr, int length, int counter){
- if(length == 0){
- if(counter < 3){
- printf("Less than 3");
- }
- return 0;
- }
- else{
- /*
- printf("Print for %d:\n", length);
- for (int i = 0; i < length; i++){
- for (int j = 0; j < length; j++){
- printf("%5d ", *(arr + i*length + j));
- }
- printf("\n");
- }
- */
- int sum = 0;
- int *one;
- one = (int*)malloc((length - 1) * sizeof(int));
- for (int i = 0; i < length - 1; i++){
- *(one + i) = *(arr + i + 1);
- }
- for (int i = 0; i < length - 1; i++){
- printf("%5d! ", *(one + i));
- if(*(one + i) % 2 != 0){
- sum += *(one + i);
- counter++;
- }
- if(counter == 3){
- return sum;
- }
- }
- printf("\n");
- int *newarr;
- newarr = (int*)malloc((length - 1) * (length - 1) * sizeof(int));
- for (int i = 0; i < length - 1; i++){
- for (int j = 0; j < length - 1; j++){
- *(newarr + i*(length - 1) + j) = *(arr + (i + 1)*(length) + j + 1);
- }
- }
- if(counter < 3){
- return sum + operation(newarr, length - 1, counter);
- }
- }
- }
- int main()
- {
- printf("Start\n");
- int *initial;
- int n;
- printf("Enter n: ");
- scanf("%d", &n);
- initial = (int*)malloc(n * n * sizeof(int));
- for (int i = 0; i < n; i++){
- for (int j = 0; j< n; j++){
- printf("arr[%d][%d] = ", i, j);
- scanf("%d", (initial + i*n + j));
- }
- }
- int counter = 0;
- int ans = operation(initial, n, counter);
- printf("\n");
- printf("Sum = %d", ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement