1030:c Language Programming Tutorial (third Edition) after class exercise 8.4

Source: Internet
Author: User

The title description writes a function that enables a given two-dimensional array (3x3) to transpose, that is, the row and column interchange. Enter a 3x3 matrix output to transpose matrices sample input
1 2 34 5 67 8 9
Sample output




1#include <stdio.h>2 3 4 voidConvertinta[][3],intRowintCol//two-dimensional array when making formal parameters, the second must be written5 {6     intI, J, temp;7      for(i =0; i < row; i + +)8     {9          for(j = i; J < Col; J + +)Ten         { One             //Exchange A             if(I! =j) -             { -temp =A[i][j]; theA[I][J] =A[j][i]; -A[j][i] =temp; -             } -         } +     } - } +  A intMainintargcChar Const*argv[]) at { -      -     //Write a function that enables a given two-dimensional array (3x3) transpose, that is, the row and column interchange -     //input -     inta[3][3], I, J; -      for(i =0; I <3; i++) in     { -          for(j =0; J <3; J + +) to         { +scanf"%d", &a[i][j]); -         } the     } *  $Convert (A,3,3);Panax Notoginseng  -     //Output the      for(i =0; I <3; i++) +     { A          for(j =0; J <3; J + +) the         { +             if(J = =0) -printf"%d", A[i][j]); $             Else $printf"%d", A[i][j]); -         } -printf"\ n");//Output Enter the     } -     return 0;Wuyi}

Description

1, in the case of a two-dimensional array of parameters, can not use a[][], form. Should use a[][2] form

2. At the time of printing the result. Each row cannot have extra spaces.

1030:c Language Programming Tutorial (third Edition) after class exercise 8.4

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.