# C Programming – HackerRank Solution | Track of the Expenditure |

### Write a Modular C Programming code to solve Track of the Expenditure Hacker Rank, A middle-class family would always like to spend money wisely

A middle-class family would always like to spend their money wisely, because of their financial status. They can’t afford to purchase luxurious items, unlike the Rich Class family. Even if they do, they do it very occasionally. In order to keep track of the expenditures of the entire year, the middle-class family maintains a record of how much they spent every month of that year. Consider for the year 2020, the family maintains a record of expenditure for each month. At the end of the year, the family would like to know the following about their expenditure.

1. Which month of the year do they spend more (display month number).
2. Which month of the year do they spend less (display month number).
3. Which are the months they spent more than 35000 rupees? (display month number).

Apply a Problem-solving framework and write a modular c program to solve the above problems.

Input Format

A number of months in the first line.

Expenditure every month in next line.

Constraints

The number of months is fixed to 12, starting from 1 to 12.

1 indicates January month, 2 indicates February month and so on to 12 indicates December month.

Output Format

First line should display month number for spent more.

Second line should display month number for spent less.

Third line should indicate month numbers spent more than 35000.

Sample Input 0

12
49832 34829 21102 58222 10238 33390 12220 47472 25000 11200 34000 29005

Sample Output 0

4
5
1 4 8

Sample Input 1

5

Sample Output 1

Expenditure should be for 12 months.

CODE:

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

{
int i;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
}

void display_a(int a[10], int n)
{
int i,j,k,l1=0,l2=0,max=0,min=999999999;
for(i=0;i<n;i++)
{
if(max<a[i])
{
max=a[i];
l1=i;
}
}
for(j=0;j<n;j++) { if(min>a[j])
{
min=a[j];
l2=j;
}
}
printf("%d\n",l1+1);
printf("%d\n",l2+1);
for(k=0;k<n;k++) { if(a[k]>35000)
{
printf("%d ",k+1);
}
}
}

int main() {

int n,a[12];
scanf("%d",&n);
if(n!=12)
{
printf("Expenditure should be for 12 months.");
exit(0);
}
display_a(a,n);
return 0;
}

OUTPUT

Congratulations, you passed the sample test case.

Click the Submit Code button to run your code against all the test cases.

Input (stdin)

12
49832 34829 21102 58222 10238 33390 12220 47472 25000 11200 34000 29005

4
5
1 4 8
Expected Output

4
5
1 4 8

Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, MISC, Solved model question papers & Hacker Rank all solutions on the below page:

Top 100+ C Programming codes – KLE Technological University