9月9日參加自考《高級程序語言1》實踐

E1:
<pre class="cpp" name="code">//e1:輸入一個n,再矩陣n*n的數,尋找到其中最小值,輸出其行和列
#include <stdio.h>
int a[1000][1000];//考試環境不允許使用變量聲明數組
void make(int n);//輸入數據
void findmin(int n);//找最小值
int main (void)
{
	int n;
	printf("please enter a number for metrix:\n");
	scanf("%d",&n);
	make(n);
	findmin(n);
	return 0;
}
void make(int n)
{
	int i,j;
	printf("please enter data:\n");
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
}
void findmin(int n)
{
	int c=0,l=0,i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(a[i][j]<a[c][l])
			{
				c=i;
				l=j;
			}			
		}
	}
	printf("hang=%d,lie=%d",c+1,l+1);
}






</pre><pre class="html" name="code" snippet_file_name="blog_20160909_4_363815" code_snippet_id="1874589">
</pre><p></p><p></p><p><pre class="cpp" name="code">//15進制轉換
#include <stdio.h>
void convert(int x);
void output(int x);
int main (void)
{
	int num;
	printf("please enter a number to convert:\n");
	scanf("%d",&num);
	if (num>9)
		convert(num);
	return 0;
}
void convert (int x)
{
	int zheng,yu;
	char fifteen;
	zheng=x/15;//1
	yu=x%15;//0
	if (zheng>15)
	{
			convert(zheng);			
	}
	else
	{
		if(zheng>9)
		{
		output(zheng);
		}
		else
		{
			printf("%d",zheng);	
		}
	}
		output(yu);
}
void output(int x)
{
	char fifteen;
	if(x>9)
	{
		if(x==10)
			fifteen='A';
		else if(x==11)
			fifteen='B';
		else if(x==12)
			fifteen='C';
		else if(x==13)
			fifteen='D';
		else if(x==14)
			fifteen='E';
		printf("%c",fifteen);
	}
	else
	{
		printf("%d",x);
	}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章