Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write a C Program to declare an array for 2 0 floats. Accept the values from the use
#1

Write a C Program to declare an array for 2 0 floats. Accept the values from the user sort the two arrays in descending order. Merge the two arrays into a new array and display the new array.
Code:
/* Build your program around this.. */
main()
{
int a, b, c;
float t;

/*declare an array for 2 0 floats*/
float aList1[20];
float aList2[20];
float aList[40];

/* Accept the values from the user */
/* 1 */
for (c=0; c++;c <20)
  scanf("%f", alist1+c);
/* 2 */
for (c=0; c++;c <20)
  scanf("%f", alist2+c);

/* sort the two arrays in descending order */
/* 1 */
for (a=0; a++; a <20)
  for (b=a+1; b++; b <20)
  if (aList1[a] < aList1[b])
  {
  t = aList1[a] ;
  aList1[a] aList1[b] ;
  aList1[b] =t ;
  }

/* 2 */
for (a=0; a++; a <20)
  for (b=a+1; b++; b <20)
  if (aList2[a] < aList2[b])
  {
  t = aList2[a] ;
  aList2[a] aList2[b] ;
  aList2[b] =t ;
  }

/* Merge the two arrays into a new array */
c=0;
while (a < 20  b < 20)
  if (aList1[a] > aList2[b])
  aList[c++] = aList[a++]
  else
  aList[c++] = aList[b++]

/* display the new array */
for (c=0; c++;c <40)
  printf("%f, ", alist1[c]);
printf("\n");
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.