Programming Lanugage must be in C Please provide the followi
Programming Lanugage must be in C. Please provide the following.
1) the number of elements. 2) the average of the elements. 3) the minimum and maximum values. 4) the second to last minimum and second to last maximum values.
HW Array input: Use this for the array:
The contents of an int array will be provided to you on eLearning. (Please check in the \"Homework Input Files\" folder of the \"Course Homepage.\" You can create and initialize an array with those contents by using an array initialization list, as follows: int main Arr copy in array contents here Every element of this array is an int between 0 and 3000, except for the last element, which is l. Since we did not provide a size declarator in the array declaration, nor do we know how many elements are in the array until we process it, that last -1 can be used as a sentinel value for our array processing. It is not considered part of the data set in the array and should not be included in the following calculations. Write a c program that scans through the array contents (everything except the -1) and determines the following statistics on it: the number of elements. l) 2) the average of the elements. 3) the minimum and maximum values. 4) the second to last minimum and second to last maximum values.Solution
first program
#include<stdio.h>
#include<dos.h>
void main()
{
int mainArr[] ={ 71, 1899, 272, 1694, 1697, 296, 722, 12, 2726, 1899,
1374, 1541, 1923, 1904, 1083, 1462, 2981, 1929, 304, 2550,
1059, 1860, 1963, 516, 647, 1607, 590, 157, 2351, 753,
2455, 349, 79, 1634, 368, 1992, 2401, 357, 1478, 1601,
239, 365, 2453, 2283, 2432, 1223, 2739, 2487, 2714, 1391,
1972, 2805, 1504, 413, 1647, 2750, 44, 64, 934, 1008,
1429, 1427, 315, 2499, 1620, 1816, 2441, 2557, 2188, 531,
1514, 2825, 449, 265, 2064, 1022, 34, 1864, 1861, 1516,
1465, 2327, 398, 2769, 563, 194, 429, 942, 1795, 223,
2406, 780, 780, 61, 133, 195, 495, 1774, 1934, 2171,
433, 1417, 292, 324, 2929, 1597, 1470, 764, 593, 891,
679, 47, 1778, 2532, 1862, 2636, 549, 2923, 2270, 1101,
1607, 2395, 726, 1111, 892, 1988, 555, 379, 224, 298,
1660, 2203, 2385, 2159, 2574, 705, 2513, 1755, 313, 173,
148, 2449, 259, 1006, 1221, 2259, 2020, 1484, 2717, 2400,
266, 1203, 2206, 357, 1294, 1153, 2820, 1858, 2062, 1499,
1422, 2343, 956, 2677, 468, 910, 2719, 1850, 825, 362,
288, 963, 843, 689, 2800, 1363, 1384, 1926, 1816, 746,
124, 2970, 1577, 2727, 1344, 276, 494, 1252, 333, 1862,
502, 2277, 890, 322, 70, 2969, 1745, 2205, 2919, 2837,
744, 203, 1699, 37, 767, 2611, 1262, 2052, 2118, 1412,
2642, 741, 1841, 1520, 892, 1659, 1030, 2016, 1158, 1566,
2070, 2272, 20, 2631, 1059, 2277, 2234, 1807, 921, 588,
965, 251, 175, 1452, 1138, 114, 648, 2223, 1509, 1513,
1061, 1221, 1035, 911, 2973, 2250, 2337, 1181, 832, 2137,
334, 1144, 1312, 2137, 2662, 2987, 778, 943, 1665, 38,
875, 1148, 2483, 2715, 814, 520, 1645, 2571, 1085, 150,
2933, 2156, 2878, 1090, 1353, 510, 2872, 1209, 801, 1518,
1805, 128, 1286, 922, 2515, 1352, 1470, 1039, 1990, 288,
2489, 2935, 1360, 819, 392, 2519, 2612, 2972, 1173, 2136,
2087, 2255, 62, 427, 1488, 1378, 798, 219, 993, 2916,
1773, 630, 1221, 1868, 1726, 1420, 1006, 2053, 2386, 1451,
2128, 1905, 2588, 1050, 1768, 1548, 284, 989, 545, 2538,
192, 2121, 2837, 251, 1720, 208, 603, 1445, 1392, 70,
2665, 507, 108, 445, 451, 470, 2814, 2278, 290, 1225,
1420, 857, 2415, 1313, 520, 1359, 666, 124, 1744, 190,
2383, 1177, 2855, 1261, 2624, 2625, 99, 2417, 1961, 1276,
769, 2447, 159, 895, 1957, 626, 2123, 1668, 2231, 1791,
974, 163, 2410, 2160, 2100, 2496, 599, 1190, 2494, 1349,
2490, 2922, 2379, 1705, 1299, 1109, 2680, 713, 1223, 2943,
2784, 550, 1615, 2853, 388, 2839, 74, 879, 734, 1432,
2031, 1073, 2611, 1939, 1566, 2535, 1687, 599, 2048, 2990,
1637, 1638, 2075, 257, 1352, 2939, 570, 1642, 1108, 2859,
1412, 1177, 392, 1643, 1996, 1682, 1136, 1339, 1042, 2106,
2229, 1890, 328, 122, 1392, 1706, 623, 823, 2703, 2693,
842, 2329, 1815, 2647, 1883, 2698, 1371, 1086, 2006, 2650,
1652, 488, 1123, 17, 290, 1324, 2495, 1221, 2361, 1244,
813, 2716, 1808, 2328, 2840, 1059, 2382, 2391, 2453, 1672,
1469, 778, 2639, 357, 2691, 1113, 2131, 23, 2535, 1514,
2317, 45, 1465, 1799, 2642, 557, 1846, 1824,1144, -1
};
int count=0,i,j;
int max=mainArr[0],min=mainArr[0];
int secondmax=mainArr[0],secondmin=mainArr[0];
long int sum=0;
float avg=0;
clrscr();
for(i=1;i>0;i++)
{
if (mainArr[i]!=-1)
{
count=count+1;
}
else
{
break;
}
}
for(i=0;i<=count;i++)
{
if(mainArr[i]>max)
{
max=mainArr[i];
}
}
for(i=0;i<=count;i++)
{
if(mainArr[i]>secondmax)
{
if(mainArr[i]<max)
{
secondmax=mainArr[i];
}
}
}
for(j=0;j<=count;j++)
{
if(mainArr[j]<min)
{
min=mainArr[j];
}
}
for(i=0;i<=count;i++)
{
if(mainArr[i]<secondmin)
{
if(mainArr[i]>min)
{
secondmin=mainArr[i];
}
}
}
for(i=0;i<=count;i++)
{
sum=sum+mainArr[i];
}
avg=sum/count;
printf(\"the sum is %ld\",sum);
printf(\"\ Total number:\\t %d\",count);
printf(\"\ Average:\\t %.1f\",avg);
printf(\"\ Min element:\\t %d\",min);
printf(\"\ Min2 element:\\t %d\",secondmin);
printf(\"\ Max element:\\t %d\",max);
printf(\"\ Max2 element:\\t %d\",secondmax);
getch();
}
second program
#include<stdio.h>
#include<dos.h>
void main()
{
int mainArr[] ={ 71, 1899, 272, 1694, 1697, 296, 722, 12, 2726, 1899,
1374, 1541, 1923, 1904, 1083, 1462, 2981, 1929, 304, 2550,
1059, 1860, 1963, 516, 647, 1607, 590, 157, 2351, 753,
2455, 349, 79, 1634, 368, 1992, 2401, 357, 1478, 1601,
239, 365, 2453, 2283, 2432, 1223, 2739, 2487, 2714, 1391,
1972, 2805, 1504, 413, 1647, 2750, 44, 64, 934, 1008,
1429, 1427, 315, 2499, 1620, 1816, 2441, 2557, 2188, 531,
1514, 2825, 449, 265, 2064, 1022, 34, 1864, 1861, 1516,
1465, 2327, 398, 2769, 563, 194, 429, 942, 1795, 223,
2406, 780, 780, 61, 133, 195, 495, 1774, 1934, 2171,
433, 1417, 292, 324, 2929, 1597, 1470, 764, 593, 891,
679, 47, 1778, 2532, 1862, 2636, 549, 2923, 2270, 1101,
1607, 2395, 726, 1111, 892, 1988, 555, 379, 224, 298,
1660, 2203, 2385, 2159, 2574, 705, 2513, 1755, 313, 173,
148, 2449, 259, 1006, 1221, 2259, 2020, 1484, 2717, 2400,
266, 1203, 2206, 357, 1294, 1153, 2820, 1858, 2062, 1499,
1422, 2343, 956, 2677, 468, 910, 2719, 1850, 825, 362,
288, 963, 843, 689, 2800, 1363, 1384, 1926, 1816, 746,
124, 2970, 1577, 2727, 1344, 276, 494, 1252, 333, 1862,
502, 2277, 890, 322, 70, 2969, 1745, 2205, 2919, 2837,
744, 203, 1699, 37, 767, 2611, 1262, 2052, 2118, 1412,
2642, 741, 1841, 1520, 892, 1659, 1030, 2016, 1158, 1566,
2070, 2272, 20, 2631, 1059, 2277, 2234, 1807, 921, 588,
965, 251, 175, 1452, 1138, 114, 648, 2223, 1509, 1513,
1061, 1221, 1035, 911, 2973, 2250, 2337, 1181, 832, 2137,
334, 1144, 1312, 2137, 2662, 2987, 778, 943, 1665, 38,
875, 1148, 2483, 2715, 814, 520, 1645, 2571, 1085, 150,
2933, 2156, 2878, 1090, 1353, 510, 2872, 1209, 801, 1518,
1805, 128, 1286, 922, 2515, 1352, 1470, 1039, 1990, 288,
2489, 2935, 1360, 819, 392, 2519, 2612, 2972, 1173, 2136,
2087, 2255, 62, 427, 1488, 1378, 798, 219, 993, 2916,
1773, 630, 1221, 1868, 1726, 1420, 1006, 2053, 2386, 1451,
2128, 1905, 2588, 1050, 1768, 1548, 284, 989, 545, 2538,
192, 2121, 2837, 251, 1720, 208, 603, 1445, 1392, 70,
2665, 507, 108, 445, 451, 470, 2814, 2278, 290, 1225,
1420, 857, 2415, 1313, 520, 1359, 666, 124, 1744, 190,
2383, 1177, 2855, 1261, 2624, 2625, 99, 2417, 1961, 1276,
769, 2447, 159, 895, 1957, 626, 2123, 1668, 2231, 1791,
974, 163, 2410, 2160, 2100, 2496, 599, 1190, 2494, 1349,
2490, 2922, 2379, 1705, 1299, 1109, 2680, 713, 1223, 2943,
2784, 550, 1615, 2853, 388, 2839, 74, 879, 734, 1432,
2031, 1073, 2611, 1939, 1566, 2535, 1687, 599, 2048, 2990,
1637, 1638, 2075, 257, 1352, 2939, 570, 1642, 1108, 2859,
1412, 1177, 392, 1643, 1996, 1682, 1136, 1339, 1042, 2106,
2229, 1890, 328, 122, 1392, 1706, 623, 823, 2703, 2693,
842, 2329, 1815, 2647, 1883, 2698, 1371, 1086, 2006, 2650,
1652, 488, 1123, 17, 290, 1324, 2495, 1221, 2361, 1244,
813, 2716, 1808, 2328, 2840, 1059, 2382, 2391, 2453, 1672,
1469, 778, 2639, 357, 2691, 1113, 2131, 23, 2535, 1514,
2317, 45, 1465, 1799, 2642, 557, 1846, 1824,1144, -1
};
int count=0,i,j;
int flag=0;
int dup_count=0;
int dup=0;
clrscr();
for(i=1;i>0;i++)
{
if (mainArr[i]!=-1)
{
count=count+1;
}
else
{
break;
}
}
for(i=0;i<=count;i++)
{
for(j=i+1;j<=count;j++)
{
if(mainArr[i]==mainArr[j])
{
if(flag==0)
{
printf(\"\ Duplicate of %d, found at index %d\",mainArr[i],j);
flag=1;
dup_count=dup_count+1;
}
else
{
printf(\", was also found at index %d.\",j);
dup_count=dup_count+1;
}
}
}
flag=0;
}
printf(\"\ Total duplicates found: %d\",dup);
getch();
}




