You are on page 1of 5

Name: Necatican Toklaç

StudentID: 2019502075

Date: 05.03.2022

Description: EED 1010 Laboratory Work#1

Task 1

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#define SIZE 10

double Calculator(int *p, int *ptotal, double *pAverage);

int i;

int main()

int arr[SIZE], Total = 0.00;

int *p, *pTotal;

double Average;

double *pAverage;

srand(time(NULL));

printf("\nThe content of the array is:\n");// displays numbers

for( i = 0; i<SIZE ; i++)

arr[i] = rand()%100; // getting random numbers


printf("%d ",arr[i]);

printf("\n\n");

p = arr; //*p points the first element

pTotal = & Total; //*pTotal points the address of the total

pAverage = &Average; // *pAverage points the address of the Average

Calculator(p,pTotal,pAverage); // Calculator() is called to find the total and the average of the
array

return 0;

// displaying results

double Calculator(int *p, int *pTotal, double *pAverage)

for(i = 0; i<SIZE;i++)

*pTotal += *(p+i);

*pAverage = (double) *pTotal / SIZE;

printf("The total of the elements in the array is: %d\n",*pTotal);


printf("The average of the elements in the array is:%.2lf\n",*pAverage);

Output of the programme

Task 2

include <stdio.h>

#include <stdlib.h>

#include <time.h>

#define SIZE 7

void reverseArray(int *ptr, int size);

void fillArray(int *ptr, int size);

void printArray(int *ptr, int size);

int main()

int a[SIZE], *p = a;

fillArray(p,SIZE);

printf("Original array: ");

printArray(p, SIZE);
reverseArray(p, SIZE);

printf("Shifted array: ");

printArray(p,SIZE);

return 0;

void fillArray(int *ptr, int size)

srand(time(NULL));

for(int i = 0; i<size;i++)

*(ptr + i) = rand()%100;

void printArray(int *ptr,int size)

for (int i = 0; i<size; i++)

printf("%d",*(ptr+i));

printf("\n");

void reverseArray(int *ptr,int size)

int temp;

for(int i=0; i < size / 2; i++)

{
temp = *(ptr +i);

*(ptr+i)= *(ptr + size-1-i);

*(ptr + size -1 -i) = temp;

I got this error. I could not get any output.

You might also like