2016.05.31 Tuesday C + + two-dimensional arrays

Source: Internet
Author: User

                                        

              Most of the code according to the book, and their own changes to write some layout and data after the results are as follows

The program code is as follows

#include <stdio.h>
#include <string.h>
#include <windows.h>
#define N 4

void Gotoxy (int x, int y)//define Gotoxy function (to move the cursor to the specified position)
{
int xx=0x0b;
HANDLE Houtput;
COORD Loc;
Loc. x = x;
Loc. Y=y;
Houtput = GetStdHandle (Std_output_handle);
SetConsoleCursorPosition (Houtput, loc);
Return
}

int main ()
{
Char name[n][20],name_t[20];
int score[n][3],sum[n];

int i,j,t;
CLRSCR ();
printf ("*********************************************************\n*\t\t\t\t\t\t\t*\n*\t\t\t\t\t\t\t*\n");
printf ("*\t\t Please enter student name and score, return end \t\t*\n*\t\t\t\t\t\t\t*\n*\t\t\t\t\t\t\t*\n*************************************** \n\n\n ");
printf ("%-12s%-12s%-12s%-12s\n\n", "name", "Language", "Mathematics", "C language");
for (i=0;i<n;i++)
{
sum[i]=0;
Gotoxy (0,10+i);
scanf ("%s", &name[i]);
for (j=0;j<3;j++)
{
Gotoxy ((j+1) *12,10+i);
scanf ("%d", &score[i][j]);
SUM[I]=SUM[I]+SCORE[I][J];
}

}
—————————————————— Data Arrangement ————————————————————
for (i=0;i<n-1;i++)
for (j=i+1;j<n;j++)
if (Sum[j]>sum[i])
{
T=sum[i];
SUM[I]=SUM[J];
sum[j]=t;
strcpy (Name_t,name[i]);
strcpy (Name[i],name[j]);
strcpy (name[j],name_t);
}

printf ("\n\n************************ score ****************************\n\n");
printf ("%-12s%-15s%-15s%-15s\n", "Rank", "name", "Total score", "average score");
for (i=0;i<n;i++)
{
printf ("%-12d%-15s%-15d%-15.2f\n", i+1,name[i],sum[i],sum[i]/3.0);
}
printf ("\n\n************************************************************\n\n");
return 0;

}

2016.05.31 Tuesday C + + two-dimensional arrays

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.