Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

raliis / IAX0584

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • IAX0584
  • rekursioon
  • m_74.c
Find file
BlameHistoryPermalink
  • raliis's avatar
    Upload New File · 825b7c7a
    raliis committed 7 years ago
    825b7c7a
m_74.c 824 Bytes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#include <stdio.h>

int scanM (); // scans the size of the array
void scanArr (int M, float *Arr); // scans in the array
int calc (float *Arr, int M); // calculates P

int main (void)
{
	int M;
	M = scanM ();

	float Arr[M];
	scanArr (M, Arr);

	double P;
	P = calc (Arr, M);
	printf ("P is equal to: %f", P);

	return 0;
}

int scanM ()
{
	int M;

	printf ("Enter the size of the array (0-51): ");
	do
	{
		scanf ("%d", &M);
	}
	while (M < 1 || M > 50);

	return M;
}

void scanArr (int M, float *Arr)
{
	int i;

	for (i = 0; i < M; i++)
	{
		printf ("Enter the %d member of the array: ", i);
		scanf ("%f", &Arr[i]);
	}

	/*for (i = 0; i < M; i++)
	{
		printf ("Element nr %d is: %.2f\n", i, Arr[i]);
	}*/
}

int calc (float *Arr, int M)
{
	int i = 0;
	double P;

	P = Arr[i] * (Arr[i+1] + Arr[i+2]);
	i++;

	return P;
}