Objective-c the sixth chapter after the class practice

Source: Internet
Author: User




Title 5: Used to flip individual bits from the terminal input number. Then modify the program so that the correct input negative number.




Code


1 int num_5 = 0, result_5 = 0;
  2           
  3 NSLog (@ "input num_5:");
  4 scanf ("% i", & num_5);
  5
  6 if (num_5 <0) // determine if it is negative
  7 {
  8 num_5 = -num_5; // If it is negative, change it to an integer first
  9 while (num_5! = 0)
10 {
11
12 result_5 = num_5% 10;
13 printf ("% i", result_5); // Use printf instead of NSLog to make the output displayed on one line
14 num_5 / = 10;
15}
16 printf ("-\ t \ n"); // Display the negative sign at the end
17}
18 else
19 {
20 while (num_5! = 0)
twenty one              {
22 result_5 = num_5% 10;
23 printf ("% i", result_5);
24 num_5 / = 10;
25}
26 printf ("\ t \ n");
27} 





Objective-c the sixth chapter after the class practice


Related Article

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.