ruby programming exercises

Want to know ruby programming exercises? we have a huge selection of ruby programming exercises information on alibabacloud.com

C Programming language Exercises 1-6

Practice 1-6 Verify that the value of the expression GetChar ()! = EOF is 0 or 1.The code is as follows:#include //contains information about the standard library. intMain ()//defines a function named Main, which does not accept parameter values. { //Verify that the value of GetChar ()! = EOF is 0 or 1. printf"Verify that the value of GetChar ()! = EOF is 0 or 1. \ n"); printf ("the validation is complete and the result is%d. \ n", GetChar ()! =EOF); Getch (); //prevent the console from fl

Introduction to C language Programming--comprehensive Exercises (iii) Student management system

C Language Student Management system:This program synthesizes the list, sorting and other knowledge, can be said to be a comprehensive exercise.# include Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. Introduction to C language Programming--comprehensive Exercises (iii) Student management system

C Programming language Exercises 1-22

Exercise 1-22 writes a program that "folds" the longer input lines into shorter two or more lines, after the last non-whitespace before the nth column of the input row. Ensure that the program intelligently handles input lines that are long and that there are no spaces or tabs in front of the columns you have set.The code is as follows:#include //contains information about the standard library. #defineMAXLINE 1000//the maximum number of characters per line is 1000. #defineBR 10//10 characters in

C Programming language Exercises 1-20

; for(i =0; I 1 (c = GetChar ())! = EOF c! ='\ n';) { if(c = ='\ t') { //If you enter a tab, the following algorithm is used to calculate how many spaces are required to fill. intj =0; J= detab-i%Detab; while(J >0) {s[i++] =' '; J--; } } Else if(c = ='\ n') {s[i++] =C; } Elses[i++] =C; } S[i]=' /'; returni;}Personal Understanding:Apply n as a symbolic constant to the global benefit of uniform modification of the program, with the number of sp

C Programming language Exercises 1-19

Exercise 1-19 writes the function reverse (s), reversing the order of characters in the string s. Use this function to write a program that reverses the order of characters in one input line at a time.The code is as follows:#include //contains information about the standard library. #defineMAXLINE 10//the maximum number of characters per line is 1000. intGetlineCharLine[],intmaxline);voidReverseCharLine[],intlen);intMain ()//defines a function named Main, which does not accept parameter values.

Web-android Engineer first-5-1 programming exercises

60, the loop performs the add-on operation and counts the number of points - - - + - + A at //print output plus score, plus number of points - - - - - } in}1 Public classHelloWorld {2 Public Static voidMain (string[] args) {3 4 //Variable Save score5 intScore = 53; 6 7 //variables are saved in addition to the number of times8 intCount = 0;9 Ten One

The 1-20 Detab of C programming exercises

can be summed up as: pos = pos + 8-(pos-1)% 8 That is, when the cursor is in POS position, enter tab, the cursor jumps to POS + 8-(pos-1)% 8 position.So the improved code is as follows:1#include 2 3 #defineTabnum 84 5 intMain ()6 {7 Chartext[ +];8 CharC;9 intindex =0;Ten intpos =1; One intSpace_number; A - while((c = GetChar ())! =EOF) - { the if(c = ='\ t') - { -Space_number = tabnum-(POS-1) %tabnum; - while(Space_number

C Programming second Edition 2.4 exercises

#include /*Rewrite Squeeze (s1,s2) to string S1 any characters in the string S2The matching characters are deleted.*/#define MAX 10Char C[max];int main () {Char A[max] = "ABCDEFG";Char B[max] = "Abcdffe";void Squeeze (char A[],char b[]);Squeeze (A, b);printf ("%s\n", c);}void squeeze (char a[], char b[]) {int i,j;int k=0;int count;for (i=0;icount=0; is importantfor (j=0;jif (a[i]! = B[j]) {//If the characters in a[i] are not equal to any of the characters in B[0]-b[9] count value plus 1count++;}

C Primer Plus 4th string and format input/output programming exercises

("Please enter first name: \ n"); scanf ("%s", lname); printf ("Please enter last name: \ n"); scanf ("%s", fname); printf ("%10s%10s\n", lname, fname); printf ("%10d%10d\n", strlen (lname), strlen (fname)); printf ("%-10s%-10s\n", lname, fname); printf ("%-10d%-10d\n", strlen (lname), strlen (fname)); return 0;}6.#include #includefloat.h>intMainvoid){ DoubleN1 =1.0/3.0; floatN2 =1.0/1.R; printf ("N1 =%.4f\n", N1); printf ("N1 =%.12f\n", N1); printf ("N1 =%.16f\n", N1); printf ("N2 =%.4f\n",

Programming Exercises: The beauty of the name

[i],1)); + } A //get the number of occurrences of all characters theIte=Mymap.begin (); + for(i=0; I) - { $Chvalue[i]=ite->second; $ite++; - } - //sort the number of occurrences of all characters the sort (chvalue,mymap.size ()); - //Calculate the beauty of a nameWuyi for(i=0; I1; i++) {//I traverse the number of mymap.size ()-1, because the last character is a line break thenvalue+= (Chvalue[i]) *K; -k--; Wu } - returnNvalue; About } $ intMain () { -U

Game Code Programming exercises

} -}The above code is a simple traversal, K is the size of n, when my k too big when the program crashes, can not solve 10e9 of the situation, so this problem cannot be solved with this idea. What to do, I think about given n when we can fall a few days according to it before and it goes up for a few days after the last fall, and the first thing I think about is the arithmetic progression summation formula, assuming there's no downside s=n+n (n-1)/2, find out that n is K days a total of

Geek programming Exercises--two number summation

TopicsEnter a specific integer value and a set of integers that require two numbers to be found in this set of integers so that the sum of the two numbers equals a specific value. Outputs all two-digit positions that meet the criteria in the previous order. The specific format is as follows:InputOutput2 53 4Analysis1) Brute force solution, Complexity O (n^2), regardless of2) hash. Use hash table to store each number corresponding subscript, complexity O (n)3) First sort, then left and right clam

Geek programming Exercises--rainwater storage problems

TopicsGiven n non-negative integers, which represent the height of the fence, calculate the amount of water the fence can hold for a given set of numbers.InputOutput6AnalysisFor each pillar, find the highest column on the left and right side, the column can accommodate the area is min (Max_left, max_right)-height. So you can scan it first, find the highest pillar, divide the array into two halves, and then handle it separately.Code#include #include using namespace STD;intMain () { vectorint>Bars

Geek programming Exercises--Hair candy problem

TopicsAssuming that n children stand in a row, each child is assigned an integer number. To give the children sugar according to the following requirements.1. Each child has at least one candy2, the number of children than the adjacent children to the candy to be moreAsk for at least a few candies to be issuedInput0 1 3 1 4Output9AnalysisCan cycle two times, the first time from the next, the next two children, the front number is larger than the number of sugar, the second pass from the back, th

C and Pointer fourth chapter programming exercises

, and copy len non-null characters to the DST array up to a maximum. After the copy is complete, the DST array must end with a null byteThe return value of the function is the length of the string stored in the DST array.If the position specified by start crosses the tail of the SRC array, or the value of start or Len is negative, then the copy to the DST array is an empty string. #include 7. Write a function to remove the extra spaces from a string. Function Prototypes:void Deblank (char string

Personal Programming Exercises

= Argparse. Argumentparser ()Parser.add_argument (' DST ')args = Parser.parse_args ()DST = Args.dstBvffer = Process_file (DST)Word_freq = Process_buffer (Bvffer)Output_result (Word_freq)Second, Code style description1. Indent with 4 spaces2. Use blank lines to separate functions and classes, and large chunks of code within functions3. Spaces are used around the operator and after commas, but no space is added to the brackets4. Fold the line to make sure it doesn't exceed 79 charactersThird, the

Web-android Engineer first-6-6 programming exercises

and assigns an initial value6 int[] Nums =New int[] {61, 23, 4, 74, 13, 148, 20 };7 8 intmax = Nums[0];//assume that the maximum value is the first element in the array9 intmin = nums[0];//assume that the minimum value is the first element in the arrayTen Doublesum = 0;//Accumulated Value One DoubleAvg = 0;//Average A - for(inti = 0; i //iterate through the elements in an array - //if the current value is greater than

Java programming ideas personal exercises

Java programming ideas personal exercises I hope you will be grateful for your criticism ......)Chapter 3 exercise 9 (1) show the maximum and minimum numbers represented by float and double indexes respectively public class MaxMinFloatDouble { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub float fmax = Flo

Objective-C Programming (Sixth Edition) Chapter 4 answers to exercises

virtual number-(void) print; // print the result-(double) Real;-(double) imaginary; @ end // -------------- implementation section ---------------- @ implementation Complex {double real; double imaginary;}-(void) setreal: (double) A {real = A;}-(void) setimaginary: (double) B {imaginary = B;}-(void) print {nslog (@ "the complex is %. F + %. fi ", real, imaginary);}-(double) Real {return real;}-(double) imaginary {return imaginary ;} @ end // ---------------- program section ------------- int ma

[C ++ primer plus] [learning C ++ from Chapter 2] -- 4. programming exercises

Programming exercises 1. Write a C ++ program that displays your name and address. // file-name: 2-7-1.cpp// Description: Display your name and address#include 2. Write a C ++ program that asks for a distance in furlongs and converts it to yards. (One Furlong is 220 yards .) // file-name: 2-7-2.cpp// Description: Ask for a distance in furlongs and convert it to yard// One forlong is 220 yard

Total Pages: 14 1 .... 9 10 11 12 13 14 Go to: Go

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.