Simple C programming Problem-same-bit equal n-sum/Standard input curly brace pair judgment/Line number line output

Source: Internet
Author: User

Find the sum of the first 5 items of SN=A+AA+AAA+AAAA+AAAAA, where a is a number, for example: 2+22+222+2222+22222#include <stdio.h>int main () { int a,n,sum;int i,j;sum = 0;printf ("Enter the number of items and the value of a"); scanf ("%d%d", &a,&n);j =  A;for (i = 1;i <= n;i++) {sum = sum+a;a = j + 10*a;} printf ("sn = %d", sum);} 2. Write a program that reads the C source code from the standard input and verifies that all curly braces are correctly paired. 0#include <stdio.h>int main () {Int c;int count;count =0;while (c =  GetChar ())  != eof) {if (c ==  ' {') count++;if (c ==  '} ') count--;} if ( 0 == count) printf ("correct"); Elseprintf ("incorrect"); return 0;} The standard input line number, then the standard output, does not limit the length of the number of rows, and then the number of lines preceded by the label #include <stdio.h> #include  <stdlib.h>int main () {Int a,c;int count;a = 1;count = 0;while ((C = getchar ())!= EOF) { if (a == 1) {a = 0;count++;p rintf ("%d", count);} Putchar (c); if (c ==  ' \ n ') {A = 1;}} return 0;} A quick sort of recursion, and output maximum minimum value #include <stdio.h>void swap (int v[],int a,int b) {int  Temp;temp = v[a];v[a] = v[b];v[b] = temp;} Void qsort (int v[],int left,int right) {int i,last;    // Last applies to subscript conversion if (left >= right)         //If the left subscript is larger than the right subscript, It jumps out of recursion Return;swap (V,left, (left+right)/2);     //based on the fast sort algorithm, first converts the first value to the middle value last = left; for (i = left +1;i <= right;i++)     //v[left] is the middle value, the remaining value is determined by the {if (V [I] < v[left]) swap (v,++last,i);             //++last}swap (V,left,last) after the remaining swap () is complete;                     //converts the leftmost and last partition values with the first step above qsort (v,left,last-1);                   //left calculates qsort (v,last+1,right);                   //to the right calculates}int main () {int  arry[10];int i;i = 0;for (i = 0;i <sizeof (Arry)/sizeof (arry[0]), i++) { scanf ("%d", &arry[i]);} Qsort (arry,0,sizeof (Arry)/sizeof (arry[0])-1);p rintf ("Maximum number is%d\n", arry[0]);p rintf ("Minimum number is%d", arry[9]); return 0 ;} The 3-digit number of 1.2.3.4 combinations is statistically #include <stdio.h>int main () {int hundreds,tens,ones;hundreds =  0;tens = 0;ones = 0;for (hundreds = 1;hundreds <= 4;hundreds  ++) {for (tens = 1;tens <= 4;tens ++) {for (ones = 1;ones <=  4;ones ++) {if (ones != tens && tens != hundreds & & hundreds != ones) {printf ("%d%d%d\n", Hundreds,tens,ones);}}} return 0;}


This article is from the "egg-left" blog, please be sure to keep this source http://memory73.blog.51cto.com/10530560/1676152

Simple C programming Problem-same-bit equal n-sum/Standard input curly brace pair judgment/Line number line output

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.