База ответов ИНТУИТ

Программирование на языке C в Microsoft Visual Studio 2010

<<- Назад к вопросам

Какие утверждения являются верными для приведенной программы?
void fillOnly(int);void free_n(int);void fill_n(int);int main (void) {	int n = 1; 	int in = 1; 	printf("\n Enter a length of string (naturel number): ");	in = scanf_s("%i", &n);	if (in != 1 || n < 1 || n > 15)     {		printf("\n Error input. Press any key to exit: ");		_getch();		exit(0);	}	puts("\n\tResult:");	fill_n(n);	printf("\n\n Press any key to exit: ");	_getch();	return 0;}void fillOnly(int n) {	if (n == 1)		printf("\t%+3d\n", 1);	else {		fillOnly(n-1);		printf("\t%+3d\n", n);		free_n(n-1);	}}void free_n(int n) {	if (n == 1)		printf("\t%+3d\n", -1);	else {		fillOnly(n-1);		printf("\t%+3d\n", -n);		free_n(n-1);	}}void fill_n(int n) {	if (n == 1)		printf("\t%+3d\n", 1);	else {		if (n == 2)			printf("\t%+3d\n\t%+3d\n", 1, 2);		else {			fillOnly(n-1);			printf("\t%+3d\n", n);			fill_n(n-2);		}	}}

(Ответ считается верным, если отмечены все правильные варианты ответов.)

Варианты ответа
в программе определено 3 рекурсивных функции(Верный ответ)
в каждой пользовательской функции используются прямая и косвенная рекурсия(Верный ответ)
в программе определено 4 рекурсивных функции
Похожие вопросы
В приведенной программе выполняется перераспределение памяти для увеличения размерности массива:
		#include <stdio.h>#include <stdlib.h>#define N 10int main(void){	int i;	int *arr = (int *)malloc(N*sizeof(int));		if (!arr) {		printf("\nERROR! Out of memory in calloc() function. Press any key: ");		_getch(); 		exit(1); 	};	for (i=0; i<N; i++) {		arr[i] = i+1;		printf("arr[%d] = %d\n", i, arr[i]);			}	arr = (int *)realloc(arr, (N+2)*sizeof(int));	if (!arr) {		printf("\nERROR! Out of memory in realloc() function. Press any key: ");		_getch(); 		exit(1); 	};	for (i=N; i<N+2; i++) {		arr[i] = i+1;		printf("arr[%d] = %d\n", i, arr[i]);	}	free(arr);	return 0;}
Какие изменения необходимо внести в программу для ее корректной работы?
Определите, что делает приведенная программа?
void printBits(unsigned int var);int main (void) {	unsigned int number1, number2;	printf("\n The program on demonstration digit-by-digit operator OR ( | ):\n");	printf("\n\t Enter the unsigned number of N1: ");	scanf_s("%u", &number1);	printf("\t Enter the unsigned number of N2: ");	scanf_s("%u", &number2);	printf("\n\t Binary representation of the number of N1 (%u) and\n", number1);	printf("\t Binary representation of the number of N2 (%u):\n", number2);	printBits(number1);	printBits(number2);	printBits(number1 | number2); 	printf("\n\n Press any key: ");	_getch();	return 0;}void printBits(unsigned int var) {	unsigned int b;	unsigned int num = 1 << 31; 	printf("\n\t %10u = ", var);	for (b = 1; b <= 32; ++b) {		printf("%c", var & num ? '1' : '0');		var <<= 1; 		if (b % 8 == 0)			putchar(' ');	} } 
При каких значениях размерности n символьного массива и строки, на которую указывает указатель ptr, в результате выполнения приведенной программы возникнет ошибка?
		#include <stdio.h>#include <conio.h>#include <stdlib.h>#include <string.h>int main(void) {	int n, m;		char *ptr; 	printf("\nEnter a dimention of character array: ");	scanf_s("%d", &n);	_flushall();	ptr = (char *)malloc((n+1)*sizeof(char));	if (!ptr) {		printf("\nERROR! Out of memmory (error in malloc() function). Press any key...");		_getch(); 		exit(1); 	}	printf("Enter a character array (not more than %d characters): ", n);	gets_s(ptr, n+1);	m = strlen(ptr);	strcat_s(ptr, m+2,  "!");	printf("\nStart line and character \"%c\": %s", '!', ptr);		free (ptr);	printf("\n\nPress any key: ");	_getch();	return 0; }
В приведенной программе выполняется перераспределение памяти для увеличения размерности массива:
		#include <stdio.h>#include <stdlib.h>#define N 10int main(void){	int i;	int *arr;	arr = (int *)realloc(arr, (N+2)*sizeof(int));	for (i=0; i<N; i++) {		arr[i] = i+1;		printf("arr[%d] = %d\n", i, arr[i]);			}	if (!arr) {		printf("\nERROR! Out of memory in realloc() function. Press any key: ");		_getch(); 		exit(1); 	};	for (i=N; i<N+2; i++) {		arr[i] = i+1;		printf("arr[%d] = %d\n", i, arr[i]);	}	free(arr);	return 0;}
Какие изменения нужно внести в программу для ее корректной работы?
В приведенной программе выполняется перераспределение памяти для увеличения размерности массива:
		#include <stdio.h>#include <stdlib.h>#define N 10int main(void){	int i;	int *arr;	for (i=0; i<N; i++) {		arr[i] = i+1;		printf("arr[%d] = %d\n", i, arr[i]);			}	arr = (int *)realloc(arr, (N+2)*sizeof(int));	if (!arr) {		printf("\nERROR! Out of memory in realloc() function. Press any key: ");		_getch(); 		exit(1); 	};	for (i=N; i<N+2; i++) {		arr[i] = i+1;		printf("arr[%d] = %d\n", i, arr[i]);	}	free(arr);	return 0;}
Определите, есть ли в этой программе ошибки?
Какое утверждение будет верным после выполнения приведенной программы?
		#include <stdio.h>#include <stdlib.h>#define N 10int main(void){	int size1, size2, size3, i, n = 0;	int arr1[N] = {1,2,3,4,5}, *arr;		size1 = sizeof(arr1);	arr = (int *)calloc(N, sizeof(int));	if (!arr) {		printf("\nERROR! Out of memory in calloc() function. Press any key: ");		_getch(); 		exit(1); 	};	for (i=0; i<N; i++) {		arr[i] = i+1;		n++;		printf("arr[%d] = %d\n", i, arr[i]);			}	size2 = N*sizeof(int);	arr = (int *)realloc(arr, (N+2)*sizeof(int));	if (!arr) {		printf("\nERROR! Out of memory in realloc() function. Press any key: ");		_getch(); 		exit(1); 	};	for (i=N; i<N+2; i++) {		arr[i] = i+1;		printf("arr[%d] = %d\n", i, arr[i]);	}	for (i=0, n=0; i<N+2; i++) n++;	size3 = n*sizeof(int);	free(arr);	return 0;}
Определите, что делает приведенная программа?
void printBits(unsigned int var);int main (void) {	unsigned int number, mask;	printf("The program on demonstration digit-by-digit operation And ( & )\n");	printf("Enter a whole number of unsigned: ");	scanf_s("%u", &number);	printf("Enter the number of unsigned-mask: ");	scanf_s("%u", &mask);	printf("Binary representation of the starting number(%u) and\n", number);	printf("Binary representation of the number-masks (%u):\n", mask);	printBits(number);	printBits(mask);	printBits(number & mask); 	return 0; }void printBits(unsigned int var) {	unsigned int b;	unsigned int mask = 1 << 15; 	printf("\n%10u = ", var);	for (b = 1; b <= 16; ++b) 	{		printf("%c", var & mask ? '1' : '0');		var <<= 1; 		if (b % 8 == 0)			putchar(' ');	}} 	
Что произойдет при выполнении приведенной программы, если пользователь задаст номер алгоритма 9?
void PuzSortInc (int*, int );void PuzSortDec (int*, int);int main (void) {	int A[] = {56, 34, 2, 0, 1, -21, 6, 8, 7};	int i, n, alg;	void (*pFun) (int*, int) = NULL;	n = sizeof(A)/sizeof(A[0]);	printf("Исходный массив: ");	for (i = 0; i < n; i++) printf(" %3d", A[i]);	printf("\nВыберите алгоритм сортировки (1 - \"методом пузырька\" по возрастанию,\		   2 - \"методом пузырька\" по убыванию: ");	scanf("%d", &alg);	switch (alg) {		case 1: pFun = PuzSortInc; break;		case 2: pFun = PuzSortDec; break;		default: printf("ERROR! Такого алгоритма не определено!"); 	}		if (pFun) {		pFun(A,n);		printf("\nSorted array: ");		for (i = 0; i < n; i++) printf(" %3d", A[i]);	};			return 0;}void PuzSortInc (int* arr, int size){	int i, j, buf; 	for (i = 0; i < size - 1; i++ ) {		for (j = 0; j < size - 1; j++) {			if (arr[j] > arr[j + 1]) {				buf = arr[j];				arr[j] = arr[j+1];				arr[j+1] = buf;			}						}	}}void PuzSortDec (int* arr, int size){	int i, j, buf; 	for (i = 0; i < size - 1; i++ ) {		for (j = 0; j < size - 1; j++) {			if (arr[j] < arr[j + 1]) {				buf = arr[j];				arr[j] = arr[j+1];				arr[j+1] = buf;			}						}	}}
Что произойдет при выполнении приведенной программы, если пользователь задаст номер алгоритма 9?
void PuzSortInc (int*, int );void PuzSortDec (int*, int);int main (void) {	int A[] = {56, 34, 2, 0, 1, -21, 6, 8, 7};	int i, n, alg;	void (*pFun) (int*, int) = NULL;	n = sizeof(A)/sizeof(A[0]);	printf("Исходный массив: ");	for (i = 0; i < n; i++) printf(" %3d", A[i]);	printf("\nВыберите алгоритм сортировки (1 - \"методом пузырька\" по возрастанию,\		   2 - \"методом пузырька\" по убыванию: ");	scanf("%d", &alg);	switch (alg) {		case 1: pFun = PuzSortInc; break;		case 2: pFun = PuzSortDec; break;		default: printf("ERROR! Такого алгоритма не определено!"); 	}	pFun(A,n);	printf("\nОтсортированный массив: ");	for (i = 0; i < n; i++) printf(" %3d", A[i]);			return 0;}void PuzSortInc (int* arr, int size){	int i, j, buf; 	for (i = 0; i < size - 1; i++ ) {		for (j = 0; j < size - 1; j++) {			if (arr[j] > arr[j + 1]) {				buf = arr[j];				arr[j] = arr[j+1];				arr[j+1] = buf;			}						}	}}void PuzSortDec (int* arr, int size){	int i, j, buf; 	for (i = 0; i < size - 1; i++ ) {		for (j = 0; j < size - 1; j++) {			if (arr[j] < arr[j + 1]) {				buf = arr[j];				arr[j] = arr[j+1];				arr[j+1] = buf;			}						}	}}
В процессе выполнения приведенной программы возникает ошибка:
		#include <stdio.h>#include <stdlib.h>#define N 10int main(void){	int i;	int *arr;		arr = (int *)calloc(N, sizeof(int));	if (!arr) {		printf("\nERROR! Out of memory in calloc() function. Press any key: ");		_getch(); 		exit(1); 	};	for (i=0; i<N+2; i++) {		arr[i] = i+1;		printf("arr[%d] = %d\n", i, arr[i]);	}	free(arr);	return 0;}
Каким образом можно изменить программу для ее корреткной работы?