1000 C language and C + + language exercises and answers #0000-0050

Source: Internet
Author: User
Tags function prototype

Collect 1000 C language and C + + language exercises (examples, written questions, programming questions, algorithmic design questions), I personally match the answer (click here). Grammar problem I will not out, that boring, reading can be.

This post collection 50 questions (0000-0050), continuously updated ...


0001. Drawing questions
Randomly extract 5 numbers from 10 numbers. (equivalent to the color Ball lottery issue)

0002. Insert Sort
There are 10 integer 1,3,5,7,9,11,13,15,17,19 arranged in ascending order. Requires inserting an integer n into the array, preserving the order of the sequence.

0003. Mathematical formula class calculation problem
The base radius of the cylinder is R, h, and the volume V is obtained. The formula gives: v = pi * r^2 * H

0004. Decomposition and resolution
Given a 10-binary integer of length 4, the individual numbers are decomposed into arrays. For example, given 1345, saved to the array int buf[4], the contents of BUF are sequentially 1,3,4,5

0005. String processing
Enter 4 strings, save them, and sort the output. For example, input dad, Baby, kitty, buy, output baby buy dad Kitty

0006. Binary conversion
Enter a 16-binary string to convert to an integer output. function prototype unsigned int hex2int (const char* str). For example, enter the string "a12b" and the function returns the integer 41259.

0007. Binary conversion
Converts a 2 binary string to an integer output. function prototype unsigned int bin2int (const char* str). For example, enter the string "101001101100001" and the function returns an integer of 12345.

0008. Algorithm design
3 votes were expressed, or 2 or more than 2 persons agreed, the vote was passed. Try to design an algorithm to calculate whether a vote is passed.

0009. String processing
Convert the date string "2015-03-18" to "2015/3/18"

0010. File operation
Enter 5 names and save them to a file

0011. File operation
A file Test.txt contains a number of name strings, one name per line. For example
Andy
Frank
John
Jennifer
Jack
Michael
Requires that all rows be read and printed to be displayed. (Number of rows unknown)

0012. Date operation
One's birthday is March 1, 1982, to find out the day is a few weeks.


1000 C language and C + + language exercises and answers #0000-0050

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.