#include<stdio.h>
#include <math.h>
#define N 6
void printSpaced(int perm[], int k, int used[]);
int main(void){
int perm[N], used[N];
for(int i=0;i<N;i++)used[i] = 0;
printSpaced(perm, 0, used);
return 0;
}
void printSpaced(int perm[], int k, int used[]){
if(k==N){
for(int i=0;i<N;i++)printf("%d
",perm[i]);
printf("\n");
return ;
}
for(int i=0;i<N;i++){
if(k==0 || (used[i]==0 &&
abs(perm[k-1] - i)>=2)){
used[i] =
1;
perm[k] =
i;
printSpaced(perm
, k+1, used);
used[i] =
0;
}
}
}
3) (10 pts) For the purposes of this question, a permutation of size n is any...
C programmning help Vector permutation can anyone explain whats happening in the bold statements ? im not too sure about it . thank you //z5285994 #include <stdio.h> #include <math.h> int main(void){ int vector_length, v1[1000], permutation[1000]; printf("Enter vector length: "); scanf("%d", &vector_length); int i; printf("Enter vector: "); for (i=1;i<= vector_length; i++){ scanf("%d",&v1[i]); } printf("Enter permutation: "); for (i = 1; i <= vector_length; i++){ scanf("%d", &permutation[i]); } for (i = 1;i <= vector_length; i++){ printf("%d ", v1[permutation[i]+1]);...
what is the output? Consider the following program: #include <stdio.h> #include <stdlib.h> #define size 3 void func(int **a) {int tmp; for (int i = 0; i < size; i++) {for (int j = i; j < size, j++) {tmp = *(*(a+i)+j); *(*(a+i)+j) = *(*(a+j)+i); *(*(a+j)+i) = tmp;}}} int main() {int **arr = malloc(sizeof(int*) * size); for(int i = 0; i < size; i++) {arr[i] = malloc(sizeof(int) * size); for (int j = 0; j < size, j++) arr[i][j] = 2*i...
How can I integrate these programs into this menu template: #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include void program_one (); void program_two (); void program_three (); void program_four(); void program_five(); int main() { int menu_option = 0; while (menu_option != 9) { printf(" = 1\n"); //Change this to your first program name. Nothing else. printf(" = 2\n"); //Change this to your second program name. Nothing else. printf(" = 3\n"); //Change this to your third program name. Nothing else. printf(" =...
10 What does the last printf in this code print to the screen? a)n-7 b)n- 0 c)n--1 d) None of the above 鬐include< stdio. h> int main) int n-0 for (n-7: n<O; n-- printf (n") printf ("n *%d", n); - return 11-What does the code print to the screen? 鬐include< stdio.h> void fun (int) int main) b) 8 d) None of the above fun (3) return void fun (int a) int x-10 while(a !_ 3 x > s} if a...
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/ /* */ /* */ /* This program computes average power, average magnitude */ /* and zero crossings from a speech signal. */ #include <stdio.h> #include <math.h> #define MAXIMUM 50 int main(void) { /* Declare variables */ int k=0, npts=30; double speech[MAXIMUM]={0.000000,-0.023438,-0.031250,-0.031250,-0.039063,-0.039063,-0.023438,0.000000,0.023438,0.070313,-0.039063,-0.039063,0.046875,0.101563,0.117188,0.101563,0.070313,0.054688,0.023438,0.000000,-0.031250,-0.039063,-0.070313,-0.070313,-0.070313,-0.070313,-0.062500,-0.046875,-0.039063,-0.031250}; /* Declare the function prototypes */ /* Compute and print statistics. */ printf("\n SPEECH DATA "); print(,,);//complete the statement printf("\n"); printf(" SPEECH STATISTICS : \n"); printf(" average power: %f \n",);//complete the statement printf(" average magnitude: %f...
Programming C....... function code is clear but compile is wrong .. I input 8 and compiled 2 0 1 1 2 3 5 8 13.. look first number 2 is wrong. The correct answer 8 is 0 1 1 2 3 5 8 13 21.. Need fix code to compile correctly.. Here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[1000]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for (...
Question 8 Predict the output of the following C program: 5 #include <stdio.h> void binaryCode(int n) printf("1"); if(n=2) return; binaryCode(n-1); int i = 0; for(; i<n;i++) printf("O"); binaryCode(n-2); } void main() { binaryCode(3); 12pt v Paragraph Β Ι Ο Avor T²v ...
9. The purpose of the following program is to generate 10 random integers, store them in an array, and then store in the freq frequency array, the number of occurrences of each number from 0 to 9. Can you find any errors in the program? If yes, correct them. #include <stdio.h> #include <stdlib.h> #include <time.h> #define SIZE 10 int main(void) int i, num, arr[SIZE], freq[SIZE]; srand (time (NULL)); arr[1] rand(); SIZE; for(i i 〈 i++) num arr[i]; freq[num]++; printf("InNumber occurrences...
Double any element's value that is less than minVal. Ex: If minVal = 10, then dataPoints = {2, 12, 9, 20} becomes {4, 12, 18, 20}. #include <stdio.h> int main(void) { const int NUM_POINTS = 4; int dataPoints[NUM_POINTS]; int minVal; int i; dataPoints[0] = 2; dataPoints[1] = 12; dataPoints[2] = 9; dataPoints[3] = 20; minVal = 10; /* Your solution goes here */ for (i = 0; i < NUM_POINTS; ++i) { printf("%d ", dataPoints[i]); } printf("\n"); return 0; }
Debug the following matrix program in C: // Program to read integers into a 3X3 matrix and display them #include <stdio.h> void display(int Matrix[3][3],int size); int main(void) { char size; double Matrix[size][size+1]; printf("Enter 9 elements of the matrix:\n"); int i; for (i = 0: i <= size: i++) { int j = 0; for (; j <= size++; j++){ scanf("%d", matrix[i--][4]) } } Display(Matrix,9); return 0; void...