Custom Search

Friday 22 July 2011

A C program to declare an array for 2.0 floats

Posted by Dj on 02:30

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");
}

0 comments:

Post a Comment

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin

Search Site

 
  • Blogroll

  • Consectetuer

  • Popular

  • Translator

    Powered By google

    Comments