1. Write a C program to output the four input integers in order from large to small?
#include <stdio.h> int main() { int num1, num2, num3, num4; // 输入四个整数 printf("请输入四个整数:\n"); scanf("%d %d %d %d", &num1, &num2, &num3, &num4); // 对输入的四个整数进行排序 if (num1 < num2) { int temp = num1; num1 = num2; num2 = temp; } if (num1 < num3) { int temp = num1; num1 = num3; num3 = temp; } if (num1 < num4) { int temp = num1; num1 = num4; num4 = temp; } if (num2 < num3) { int temp = num2; num2 = num3; num3 = temp; } if (num2 < num4) { int temp = num2; num2 = num4; num4 = temp; } if (num3 < num4) { int temp = num3; num3 = num4; num4 = temp; } // 输出排序后的结果 printf("按从大到小的顺序输出:%d %d %d %d\n", num1, num2, num3, num4); return 0; }
2. Randomly input 4 integers and output them from large to small using conditional statements to program?
When the input situation is random, we can use conditional statements to sort. The following is an example:
#include <stdio.h> int main() { int num1, num2, num3, num4; // 模拟随机输入四个整数 printf("模拟随机输入四个整数:\n"); scanf("%d %d %d %d", &num1, &num2, &num3, &num4); // 使用条件语句进行排序 if (num1 < num2) { int temp = num1; num1 = num2; num2 = temp; } if (num1 < num3) { int temp = num1; num1 = num3; num3 = temp; } if (num1 < num4) { int temp = num1; num1 = num4; num4 = temp; } if (num2 < num3) { int temp = num2; num2 = num3; num3 = temp; } if (num2 < num4) { int temp = num2; num2 = num4; num4 = temp; } if (num3 < num4) { int temp = num3; num3 = num4; num4 = temp; } // 输出排序后的结果 printf("按从大到小的顺序输出:%d %d %d %d\n", num1, num2, num3, num4); return 0; }
3. C# inputs four integers and outputs them from large to small?
using System; class Program { static void Main() { Console.WriteLine("请输入四个整数,用空格分隔:"); string[] input = Console.ReadLine().Split(' '); // 将输入的字符串转换为整数数组 int[] numbers = new int[input.Length]; for (int i = 0; i < input.Length; i++) { numbers[i] = int.Parse(input[i]); } // 使用Array.Sort方法对整数数组进行排序 Array.Sort(numbers); // 按从大到小的顺序输出 Console.WriteLine("按从大到小的顺序输出:{0} {1} {2} {3}", numbers[3], numbers[2], numbers[1], numbers[0]); } }
Summary:
The above are three programs written in C and C#, which respectively demonstrate the manual input of four integers for sorting and the random input of four Integer sorting method. The built-in Array.Sort
method is used in C# to sort an integer array. The idea of sorting is to compare the sizes and then exchange positions, and the final output is in order from large to small.
The above is the detailed content of C program: output of four integers in descending order. For more information, please follow other related articles on the PHP Chinese website!

This article addresses the Windows "INVALID_DATA_ACCESS_TRAP" (0x00000004) error, a critical BSOD. It explores common causes like faulty drivers, hardware malfunctions (RAM, hard drive), software conflicts, overclocking, and malware. Trou

This article provides practical tips for maintaining ENE SYS systems. It addresses common issues like overheating and data corruption, offering preventative measures such as regular cleaning, backups, and software updates. A tailored maintenance s

This article identifies five common pitfalls in ENE SYS implementation: insufficient planning, inadequate user training, improper data migration, neglecting security, and insufficient testing. These errors can lead to project delays, system failures

Article discusses editing Windows Registry, precautions, backup methods, and potential issues from incorrect edits. Main issue: risks of system instability and data loss from improper changes.

What does the drive health warning in Windows Settings mean and what should you do when you receive the disk warning? Read this php.cn tutorial to get step-by-step instructions to cope with this situation.

Article discusses managing Windows services for system health, including starting, stopping, restarting services, and best practices for stability.

This article identifies ene.sys as a Realtek High Definition Audio driver component. It details its function in managing audio hardware, emphasizing its crucial role in audio functionality. The article also guides users on verifying its legitimacy

This article addresses the failure of the Windows asio.sys audio driver. Common causes include corrupted system files, hardware/driver incompatibility, software conflicts, registry issues, and malware. Troubleshooting involves SFC scans, driver upda


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
