# C Some simple exercises, about Narcissus number, summation, integer high and low bit output, make bits replacement

Source: Internet
Author: User

`#define &NBSP;_CRT_SECURE_NO_WARNINGS//output An integer for each bit//1. Low output to high #include <stdio.h> #include  < Stdlib.h>int main () {int a;printf ("Please output a number"), scanf ("%d", &a), while (a) {printf ("%d ", a % &NBSP;10); a = a / 10;} System ("pause"); return 0;} 2. High output to low #include <stdio.h> #include  <stdlib.h> #include  <math.h>int main ( {int a,b;int count = 0;printf ("Please enter a number"), scanf ("%d", &a); B = a;while (b) {count  ++;b =  (b/ 10);} printf ("%d", (int) pow (10,count-1)), while (count) {b = a /  (int) pow (10,count-1); a =  a - b* (int) pow (10,count-1);p rintf ("%d ", b); count --;} System ("pause"); return 0;} Calculate 1-1/2+1/3-1/4+1/5....-1/100#include <stdio.h> #include  <stdlib.h>int main () { Double sum,a,b,c;sum = 1;a = 2.0;b = 1.0;c = 1;  while ( A&NBSP;&LT;=&NBSP;100){c = -c;sum = sum +  (c *  (b/a)); a ++;} printf ("%f", sum); System ("pause"); return 0;} #include  <stdio.h> #include  <stdlib.h>int main () {int i,count;count =  0;//for (i = 9;i <= 99;i += 10)//Fool algorithm//{//count++;//}//for (i = 90;i  < 100;i++)//{//count++;//}for (i = 9;i < 100;i++) {if (i / 10  == 9) count++;if (i % 10 == 9) count++;} printf ("%d", count); System ("pause"); return 0;} Output triangle #include <stdio.h> #include  <stdlib.h>int main () {int line,i,j,k,p;scanf ( "%d", &line);p  = line;for (j = 1;j <= line;j++) {for (i = 0;i  < p;i++) {printf (" ");} For (k = 1;k <=  (j - 1) *2+1;k++) {printf ("*");} p--;p rintf ("\ n");} System ("pause"); return 0;//the number of daffodils #include <stdio.h> #include  <stdlib.h> #include  <math.h>int main () {int hundreds,tens,ones,i;i =0;for (i  = 100;i<999;i++) {hundreds=i/100;tens=i/10-hundreds*10;ones=i%10;if (POW (hundreds,3) +pow (tens,3) + Pow (ones,3)  == i) printf ("%d ", I);} System ("pause"); return 0 ;} Remove 1 of an integer bits, return an integer #include <stdio.h> #include  <stdlib.h> #include  <math.h>int  main () {int num,i;printf ("Enter an integer:"), scanf ("%d", &num);p rintf ("Select the number of bits to remove binary 1:"); scanf ("%d", &i );p rintf ("%d",num &  (POW (2,i-1))), System ("pause"); return 0 ;}`

C Some simple exercises, about Narcissus number, summation, integer high and low bit output, make bits replacement

Related Keywords:
Related Article

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.