مثال دریافت n عدد اعشاری به کمک اشاره گر، مرتب سازی حبابی آنها و نمایش خروجی:
#include "stdafx.h" #include <iostream> int main() { /*int x = 10, y = 21; float z = (float)y / x; //remove (float) and see the results x = (int)z; printf("z = %.f", z);*/ unsigned long N = 0; printf("Please enter N:\n"); GET_N: scanf_s("%ld", &N); if (N < 1) { printf("Invalid size, try again\n"); goto GET_N; } printf("\nEnter %d Numbers: ", N); double* data = new double[N]; memset(data, 0, N * sizeof(double)); for (int i = 0; i < N; i++) scanf_s("%lf", &data[i]); for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (data[j] > data[i]) { double t = data[i]; data[i] = data[j]; data[j] = t; } } } printf("Sorted output:\n"); for (int i = 0; i < N; i++) printf("%.2lf, ", data[i]); std::cin.ignore(); getchar(); return 0; }