Day_6 n*n Multiplication Table

1. Implement a function, print multiplication tables, and specify the number of rows and columns of the tables.
Input 9, output 99 recipe tables, input 12, output 1212 multiplication recipe tables.
This program can refer to the code of the Nine-Nine Multiplication Table. It only needs to define an additional N typed from the keyboard. The source code is as follows:

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
int Multiply(int n){
	int i, j;
	for (i = 0; i <= n; i++){
		for (j = 0; j <= i; j++){
			printf("%d*%d=%2d  ", i, j, i*j);
		}
		printf("\n");
	}
}
void main(){
	int n;
	printf("Please enter the table you want to know:\n");
	scanf("%d", &n);
	Multiply(n);
	system("pause");
}

2. Use function to exchange two numbers.
With reference to the function, the source code is as follows:

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <stdlib.h>

int Swap(int* i, int* j){
	int temp;
	temp = *i;
	*i = *j;
	*j = temp;
}
void main(){
	int a, b;
	printf("Please enter the number:\n");
	scanf("%d%d", &a, &b);
	Swap(&a, &b);
	printf("%d %d\n", a, b);
	system("pause");
}

3... Implement a function to determine whether year is a leap year.

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
int Runyear(int* year){
	if ((*year % 4 == 0 && *year % 100 != 0) || (*year % 400 == 0)){
		printf("It's a leap year!\n");
	}
	else
		printf("It's not a leap year!\n");
}

void main(){
	int year;
	printf("Please enter the year you need to calculate: ");
	scanf("%d", &year);
	Runyear(&year);
	system("pause");
}

4. Create an array.
The implementation function init () initializes the array,
Implement empty () to empty the array,
Implement reverse () function to complete the inversion of array elements.
Requirements: Design the parameters of the function and return the value.
In this program, I made an optional menu, the source code is as follows:

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
int Inint(int arr[]){
	int i = 0;
	for (i = 0; i <= 9; ++i){
		arr[i] = 1;
		printf("%d", arr[i]);
	}
}
int CleanArr(int arr[]){
	int i = 0;
	for (i = 0; i <= 9; ++i){
		arr[i] = 0;
		printf("%d", arr[i]);
	}
}
int ReverseArr(int arr[],int length){
	int i;
	int left, right;
	left = 0;
	int tmp = 0;
	right = length - 1;
	
		for (i= 0; i <= length-1; i++){
			while (left <= right){

				tmp = arr[left];
				arr[left] = arr[right];
				arr[right] = tmp;
				left++;
				right--;
			}
			printf("%d", arr[i]);
	}
}
void main(){
	int arr[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	int a;
	printf("***********************\n");
	printf("******1 Initialize arrays*****\n");
	printf("******2 Empty array ******\n");
	printf("******3 Array inversion ******\n");
	printf("***********************\n");
	scanf("%d", &a);
	switch (a){
	case 1:
		Inint(arr);
		break;
	case 2:
		CleanArr(arr);
		break;
	case 3:
		ReverseArr(arr, 10);
		break;
	default:
		printf("Your input is incorrect. Please re-enter: ");
		break;
	}
	system("pause");
}

5. Implement a function to determine whether a number is a prime number.
Update on old issues:

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
int Prime(int i){
	int j;
	for (j = 2; j <i; j++){
		if (i%j == 0){
			break;
		}
	}
	if (i == j){
		printf("It's prime!\n");
	}
	else
		printf("Not prime!\n");

}
void main(){
	int i;
	printf("Please enter the number you are looking for:\n");
	scanf("%d", &i);
	Prime(i);
	system("pause");
}

End, Bixin~

Posted by irken on Tue, 26 Mar 2019 22:36:29 -0700