first commit
This commit is contained in:
		
						commit
						3d7815da13
					
				
							
								
								
									
										54
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,54 @@ | ||||
| # ---> C | ||||
| # Prerequisites | ||||
| *.d | ||||
| 
 | ||||
| # Object files | ||||
| *.o | ||||
| *.ko | ||||
| *.obj | ||||
| *.elf | ||||
| 
 | ||||
| # Linker output | ||||
| *.ilk | ||||
| *.map | ||||
| *.exp | ||||
| 
 | ||||
| # Precompiled Headers | ||||
| *.gch | ||||
| *.pch | ||||
| 
 | ||||
| # Libraries | ||||
| *.lib | ||||
| *.a | ||||
| *.la | ||||
| *.lo | ||||
| 
 | ||||
| # Shared objects (inc. Windows DLLs) | ||||
| *.dll | ||||
| *.so | ||||
| *.so.* | ||||
| *.dylib | ||||
| 
 | ||||
| # Executables | ||||
| *.exe | ||||
| *.out | ||||
| *.app | ||||
| *.i*86 | ||||
| *.x86_64 | ||||
| *.hex | ||||
| 
 | ||||
| # Debug files | ||||
| *.dSYM/ | ||||
| *.su | ||||
| *.idb | ||||
| *.pdb | ||||
| 
 | ||||
| # Kernel Module Compile Results | ||||
| *.mod* | ||||
| *.cmd | ||||
| .tmp_versions/ | ||||
| modules.order | ||||
| Module.symvers | ||||
| Mkfile.old | ||||
| dkms.conf | ||||
| 
 | ||||
							
								
								
									
										34
									
								
								arrays.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								arrays.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | ||||
| #include <stdlib.h> | ||||
| #include <stdio.h> | ||||
| #include "arrays.h" | ||||
| 
 | ||||
| void fill_array(int* arr){ | ||||
| 	#if _ARR_SIZE > 5 | ||||
| 		for(int i = 0; i < _ARR_SIZE; i++){ | ||||
| 			arr[i] = rand()%20-9; | ||||
| 		} | ||||
| 	#else | ||||
| 		for(int i = 0; i < _ARR_SIZE; i++){ | ||||
| 			printf("Введите значение для элемента %d: ", i); | ||||
| 			scanf("%d", &arr[i]);	 | ||||
| 		} | ||||
| 	#endif | ||||
| } | ||||
| 
 | ||||
| void print_array(int* arr){ | ||||
| 	printf("["); | ||||
| 	for(int i = 0; i < _ARR_SIZE; i++){ | ||||
| 		printf("%+d, ", arr[i]); | ||||
| 	} | ||||
| 	printf("\b\b]\n"); | ||||
| } | ||||
| 
 | ||||
| void print_pointer(int index){ | ||||
| 	if(index<0){ | ||||
| 		return; | ||||
| 	} | ||||
| 	for(int i = 0; i < index; i++){ | ||||
| 		printf("    "); | ||||
| 	} | ||||
| 	printf("  ^\n"); | ||||
| } | ||||
							
								
								
									
										8
									
								
								arrays.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								arrays.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | ||||
| #ifndef ARRAYS_H_ | ||||
| #define ARRAYS_H_ | ||||
| #define _ARR_SIZE 10 | ||||
| 
 | ||||
| void fill_array(int* arr); | ||||
| void print_array(int* arr); | ||||
| void print_pointer(int index); | ||||
| #endif | ||||
							
								
								
									
										37
									
								
								main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								main.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,37 @@ | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <time.h> | ||||
| #include "progs.h" | ||||
| 
 | ||||
| int main() { | ||||
| 	int prog_number; | ||||
| 
 | ||||
| 	srand(time(NULL)); | ||||
| 	 | ||||
| 	printf("Лабораторная работа №2\n\nВариант №2, 6106, автор: Морозов Иван\n\n"); | ||||
| 
 | ||||
| 	printf("Выберите программу: \n\n"); | ||||
| 
 | ||||
| 	printf("1. Программа для нахождения минимального чётного отрицательного элемента массива.\n"); | ||||
| 	printf("2. Программа для нахождения индекса первого положительного чётного элемента массива.\n"); | ||||
| 	printf("3. Программа для вычисления суммы N членов ряда\n"); | ||||
| 
 | ||||
| 	prog_number = getchar()-'0'; | ||||
| 	system("clear"); | ||||
| 
 | ||||
| 	switch(prog_number){ | ||||
| 		case 1: | ||||
| 			prog1(); | ||||
| 			break; | ||||
| 		case 2: | ||||
| 			prog2(); | ||||
| 			break; | ||||
| 		case 3: | ||||
| 			prog3(); | ||||
| 			break; | ||||
| 		default: | ||||
| 			printf("Ошибка: недопустимый номер программы!\n"); | ||||
| 			return 1; | ||||
| 	} | ||||
| 	return 0; | ||||
| } | ||||
							
								
								
									
										28
									
								
								prog1.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								prog1.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include "progs.h" | ||||
| #include "arrays.h" | ||||
| 
 | ||||
| void prog1(){ | ||||
| 	int arr[_ARR_SIZE];	fill_array(arr); | ||||
| 	int index = -1; | ||||
| 	int value = 0; | ||||
| 	 | ||||
| 	for(int i = 0; i < _ARR_SIZE; i++){ | ||||
| 		if(arr[i]<value && arr[i]<0 && (arr[i]&1)==0){ | ||||
| 			index = i; | ||||
| 			value = arr[i]; | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	#if _ARR_SIZE <= 10 | ||||
| 		print_array(arr); | ||||
| 		print_pointer(index); | ||||
| 	#endif | ||||
| 	 | ||||
| 	if(index>=0){ | ||||
| 		printf("Минимальный чётный отрицательный элемент равен %d\n", value); | ||||
| 	} else{ | ||||
| 		printf("В массиве нет ни одного элемента, подходящего под условия\n"); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										27
									
								
								prog2.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								prog2.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include "progs.h" | ||||
| #include "arrays.h" | ||||
| 
 | ||||
| void prog2(){ | ||||
| 	int arr[_ARR_SIZE];	fill_array(arr); | ||||
| 	int index = -1; | ||||
| 	 | ||||
| 	for(int i = 0; i < _ARR_SIZE; i++){ | ||||
| 		if(arr[i] > 0 && (arr[i]&1)==0){ | ||||
| 			index = i; | ||||
| 			break; | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	#if _ARR_SIZE <= 10 | ||||
| 		print_array(arr); | ||||
| 		print_pointer(index); | ||||
| 	#endif | ||||
| 	 | ||||
| 	if(index>=0){ | ||||
| 		printf("Первый положительный чётный элемент имеет индекс %d\n", index); | ||||
| 	} else{ | ||||
| 		printf("В массиве нет ни одного элемента, подходящего под условия\n"); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										23
									
								
								prog3.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								prog3.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include "progs.h" | ||||
| 
 | ||||
| void prog3(){ | ||||
| 	double sum, last, x; | ||||
| 	unsigned int n; | ||||
| 	printf("Программа приближённо рассчитает сумму N членов ряда.\nВведите данные.\n"); | ||||
| 	printf("x: "); scanf("%lf", &x); | ||||
| 	printf("N: "); scanf("%ud", &n); | ||||
| 	sum = 1; | ||||
| 	last = 1; | ||||
| 	for(unsigned int i = 1; i<=n; i++){ | ||||
| 		double now = last*(-(x*x)/(2*i*(2*i-1))); | ||||
| 		sum+=now; | ||||
| 		last=now; | ||||
| 	} | ||||
| 	printf("Сумма %d членов ряда при x=%lf равна %lf\n", n, x, sum); | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
| 
 | ||||
| */ | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user