⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4_2.cpp

📁 这是一个矩阵乘法 程序
💻 CPP
字号:
/*第2题	矩阵乘法--源代码及关键源代码注解如下:*/
#include <iostream.h>
#include <conio.h>
void main()
    {
    	int r,c,a[5][5],b[5][5],d[5][5];
    	for (r=0;r<5;r++)
    		for(c=0;c<5;c++)
    			a[r][c]=r*5+c+1;
    //output array a
    cout<<endl<<" Array a\n\n";
    for(r=0;r<5;r++)
        {
        	for (c=0;c<5;c++)
            	{
            		if(a[r][c]<10)
            			cout<< " " << a[r][c] <<" ";
            		else
            			cout<<a[r][c]<<" ";
            	}
            	cout<<endl;
        }
        int choice;
        cout<< "\nPick an angle of rotation \n";
        cout<< "1 - 90 degrees\n";
        cout<< "2 - 180 degrees\n";
        cout<< "3 - 270 degrees\n";
        cin>>choice;
        if (choice==1)
            {
            	//fill array b, turn array a 90 degrees
            	for (r=0;r<5;r++)
            			for (c=0;c<5;c++)
            				b[4-c][r]=a[r][c];
        }
        if (choice==2)
            {
            	//fill array b, turn array a 180 degrees
            	for (r=0;r<5;r++)
            			for (c=0;c<5;c++)
            				b[4-r][4-c]=a[r][c];
        }
        if (choice==3)
            {
            	//fill array b, turn array a 270 degrees
            	for (r=0;r<5;r++)
            			for (c=0;c<5;c++)
            				b[c][4-r]=a[r][c];
        }
        cout<<endl<<" Array b\n\n";
        for (r=0;r<5;r++)
            {
            	for (c=0;c<5;c++)
                	{
                		if(b[r][c]<10)
                			cout<< " " << b[r][c] <<" ";
                		else
                			cout<<b[r][c]<< " ";
                	}
                	cout<<endl;
            }
            int choice2;
            cout<< "\nPick an angle of reflection and point\n";
            cout<< "1 - x-axis\n";
            cout<< "2 - y-axis\n";
            cout<< "3 - Point\n";
            cin>>choice;
            if (choice==1)
                { 	//fill array d, reflect array
                	for (r=0;r<5;r++)
                			for (c=0;c<5;c++)
                				d[r][c]=b[4-r][c];
            }
            if (choice==2)
                { 	//fill array b, turn array a 180 degrees
                	for (r=0;r<5;r++)
                			for (c=0;c<5;c++)
                				d[r][c]=b[r][4-c];
            }
            if (choice==3)
                { 	//fill array b, turn array a 180 degrees
                	for (r=0;r<5;r++)
                			for (c=0;c<5;c++)
                				d[r][c]=b[4-r][4-c];
            }
            cout<<endl<<" Array d\n\n";
            for (r=0;r<5;r++)
                {
                	for (c=0;c<5;c++)
                    	{
                    		if(d[r][c]<10)
                    				cout<< " " << d[r][c] <<" ";
                    		else
                    			cout<<d[r][c]<< " ";
                    	}
                    	cout<<endl;
                }
            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -