Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

functions 2_3

#include <stdio.h>
#include <stdlib.h>

int* Square(int* arr, int size){
    int i;
    int* x;
    x = malloc(sizeof(int) * size);
    for(i = 0; i < size; i++){
        x[i] = arr[i] * arr[i];
    }
    return x;
}

int main()
{
    int* arr = malloc(sizeof(int) * 5);
    int* x;
    int i;
    
    for (i = 0; i < 5; i++){
        arr[i] = i;
    }
    
    x = Square(arr, 5);
    
    for(i = 0; i < 5; i++){
        printf("\nThe square of %d is %d", arr[i], x[i]);
    }
    return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.