#include <stdio.h> #include <string.h> #define MAX_FRAMES 10 // Function to sort frames based on sequence numbers void sortFrames(int sequence[], char content[][100], int totalFrames) { for (int i = 0; i < totalFrames - 1; i++) { int minIndex = i; for (int j = i + 1; j < totalFrames; j++) { if (sequence[j] < sequence[minIndex]) { minIndex = j; } } // Swap sequence numbers int tempSeq = sequence[i]; sequence[i] = sequence[minIndex]; sequence[minIndex] = tempSeq; // Swap corresponding content char tempContent[100]; strcpy(tempContent, content[i]); strcpy(content[i], content[minIndex]); strcpy(content[minIndex], tempContent); } } int main() { int totalFrames; // Get the number of frames printf("How many frames do you want to enter? (max 10): "); scanf("%d", &totalFrames); int sequenceNumbers[totalFrames]; // Array for frame sequence numbers char frameData[totalFrames][100]; // Array for frame content (data) // Get input for each frame for (int i = 0; i < totalFrames; i++) { printf("\nEnter data for frame %d: ", i + 1); scanf("%s", frameData[i]); // Input the content of the frame printf("Enter sequence number for frame %d: ", i + 1); scanf("%d", &sequenceNumbers[i]); // Input the sequence number } // Sort frames by their sequence number sortFrames(sequenceNumbers, frameData, totalFrames); // Display sorted frames printf("\nSorted Frames by Sequence Number:\n"); for (int i = 0; i < totalFrames; i++) { printf("Frame %d: Sequence Number: %d, Data: %s\n", i + 1, sequenceNumbers[i], frameData[i]); } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter