Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WRITE A C PROGRAM: TEMPLATE: #include #include void readPerm(int perm[], int len); int checkPerm(const int perm[], int len); int main() { int length; int readOK;

WRITE A C PROGRAM:

image text in transcribed

image text in transcribed

TEMPLATE:

#include

#include

void readPerm(int perm[], int len);

int checkPerm(const int perm[], int len);

int main()

{

int length;

int readOK;

readOK = scanf("%d", &length);

while (readOK && (length > 0)) {

int perm[length+1];

readPerm(perm, length);

int isSuper = checkPerm(perm, length);

printf("%ssuper ", (isSuper ? "" : "not "));

readOK = scanf("%d", &length);

}

return 0;

}

/*

Read len integers, and save them to perm[1], perm[2], and so on.

perm has (len + 1) elements. 0, 1, ..., len.

perm[0] is not used. It is safe to write to perm[len].

*/

void readPerm(int perm[], int len)

{

// Write a loop to read len integers.

// In each iteration, use scanf to read an integer into

// a temporary variable, and then copy it to the right

// element in the array.

// Remember to start with perm[1].

// TODO

}

// return 1 for superpermutations, 0 otherwise.

// remember

// 1. perm has (len + 1) elements. perm[0] is not used.

// 2. check if the value is between 1 and len.

int checkPerm(const int perm[], int len)

{

// TODO

int isSuper = 1;

return isSuper;

}

A permutation of the integers from 1 to n is an ordering of these integers. A natural way to represent a permutation is to list the integers in the desired order. For example, for n = 5, a permutation might look like 2, 3, 4, 5, 1. However, there is alternative way of representing a permutation: you create a list of n numbers where the i-th number is the position of integer i in the permutation. For the above permutation this alternative representation is 5, 1, 2, 3, 4 since 1 appears on position 5, 2 appears on position 1, and so on (note that in math position numbering starts from 1). A super-permutation is a permutation for which the two representations are identical. For example, 1, 4, 3, 2 is a super-permutation. You have to write a program which detects if a given permutation is a super-permutation or not. A template is provided. Do not modify main) in the template. Input: The program should read from the standard input one or more test cases. In each case, the program first reads an integer n (1 <>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ehs 2.0 Revolutionizing The Future Of Safety With Digital Technology

Authors: Tony Mudd

1st Edition

B0CN69B3HW, 979-8867463663

More Books

Students also viewed these Databases questions

Question

4 How do Interpretive tasks help learners for Mediation?

Answered: 1 week ago

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago