Programming in C question!!!!!!! I did part 1&2 together, and part 3 seperate. a
ID: 3677527 • Letter: P
Question
Programming in C question!!!!!!! I did part 1&2 together, and part 3 seperate. apparently part 3 is the only code needed to be submitted. i put together the code, but it doesnt work :/
-attached are the directions
//PART1&2
#include <stdio.h>
#include <stdlib.h>
int main()
{
int array[100], maximum, size, c, location = 1;
int position
printf("Enter the number of elements in array ");
scanf("%d", &size);
printf("Enter %d integers ", size);
for (c = 0; c < size; c++)
scanf("%d", &array[c]);
printf(u201center a given positionu201d);
scanf("%d", &position);
largest(array,size,position);
void largest(int array[],int size,int position)
{
maximum = array[position];
for (c = position; c < size; c++)
{
if (array[c] > maximum)
{
maximum = array[c];
location = c+1;
}
}
printf("Maximum element is present at location %d and it's value is %d. ", location, maximum);
return 0;
}}
//PART3
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
int main()
{
int array[100], maximum, size, c, location = 1;
int position
printf("Enter the number of elements in array ");
scanf("%d", &size);
printf("Enter %d integers ", size);
for (c = 0; c < size; c++)
scanf("%d", &array[c]);
printf(u201center a given positionu201d);
scanf("%d", &position);
largest(array,size,position);
void largest(int array[],int size,int position)
{
maximum = array[position];
for (c = position; c < size; c++)
{
if (array[c] > maximum)
{
maximum = array[c];
location = c+1;
}
}
printf("Maximum element is present at location %d and it's value is %d. ", location, maximum);
return 0;
}
void main()
{
int i, j, a, n, number[30];
do
{
printf("Enter the value of N :");
scanf("%d", &n);
if(n>=2&&n<=15)
{
break;
}
else
{
printf(" Error: value must be 2 to 15 Try Again...");
}
}
while(1);
printf("Enter the numbers ");
for (i = 0; i < n; ++i)
{
scanf("%d", &number[i]);
}
printf("Before Sorting:");
for (i = 0; i < n; ++i)
printf("%d ", number[i]);
printf(" ");
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (number[i] < number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
printf("After Sorting:");
for (i = 0; i < n; ++i)
printf("%d ", number[i]);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.