Program Console Vignaankosh.com
Execution Panel
Console is empty.
Sort records using function is an interactive C dry run visualizer from the Struct Functions Pointers programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.
This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.
#include <stdio.h>
#include <string.h>
struct Product {
int code;
char name[50];
float price;
};
void sortByPrice(struct Product arr[], int size) {
struct Product temp;
for(int i = 0; i < size-1; i++) {
for(int j = 0; j < size-i-1; j++) {
if(arr[j].price > arr[j+1].price) {
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
void displayProducts(struct Product arr[], int size) {
printf("\n%-10s %-30s %-10s\n", "Code", "Product Name", "Price");
printf("------------------------------------------------\n");
for(int i = 0; i < size; i++) {
printf("%-10d %-30s ₹%-10.2f\n",
arr[i].code, arr[i].name, arr[i].price);
}
}
int main() {
struct Product products[5] = {
{104, "Mouse", 599.00},
{101, "Keyboard", 1299.00},
{105, "Monitor", 8999.00},
{102, "CPU", 24999.00},
{103, "Printer", 4999.00}
};
printf("Before Sorting:");
displayProducts(products, 5);
sortByPrice(products, 5);
printf("\nAfter Sorting by Price (Ascending):");
displayProducts(products, 5);
return 0;
}