General test and Machine Test

Source: Internet
Author: User

I. Auto-increment and auto-increment operations

++ I: I increases by 1 and then participates in other operations.
-- I: I minus 1 and then participates in other operations.
I ++: After I is involved in the operation, the value of I increases by 1.
I --: After I is involved in the operation, the value of I is reduced by 1.

Ii. integer-based floating point number in C Language

Two methods:

1. Float F = .....;
Int I = (INT) (F + 0.5 );
I is the result of rounding F.

2. Use library functions

Floor: round down
Floor (2.6) = 2
Floor (-2.6) =-3
Ceil: rounded up
Ceil (2.3) = 3
Ceil (-2.3) =-3
Be sure to include the header file math. h.
References:
1. http://topic.csdn.net/t/20050203/14/3773229.html
2. http://zhidao.baidu.com/question/155536957.html
3. http://www.360doc.com/content/11/0429/17/3931678_113204596.shtml

III. C language variable Memory Allocation

References:

1. http://blog.csdn.net/subo86/article/details/4814874

2. http://topic.csdn.net/t/20051110/09/4383464.html

3. http://zhidao.baidu.com/question/52843150.html

Iv. number of replies

1. determine whether an integer is a return number:

# Include <stdio. h> void main () {int I, num, new_num = 0, temp = 0; printf ("Enter the number to be judged:"); scanf ("% d ", & num); temp = num; // convert the number of inputs into the reverse! = 0) {int gewei = TEMP % 10; new_num = new_num * 10 + gewei; temp = temp/10 ;} // If a number is the same as the original number, if (num = new_num) {printf ("% d", num ); printf ("this number is the number of input \ n");} else {printf ("% d", num); printf ("this number is not the number of input \ n ");}}

References: http://topic.csdn.net/u/20080331/22/d36bf390-944e-432b-a31b-d186dd4db4d0.html

2. Determine whether a string is a return number:

# Include <stdio. h ># include <string> void daozhi (char STR []) {int I, n; char C, * s = STR; For (n = 0; s [N]! = '\ 0';) n ++; printf ("n = % d \ n", n); for (I = 0; I <= n/2; I ++) {c = STR [I]; STR [I] = STR [n-i-1]; STR [n-i-1] = C ;}} void main () {char str1 [100], str2 [100]; int A; gets (str1); strcpy (str2, str1); daozhi (str2); A = strcmp (str1, str2); if (a = 0) printf ("% s is input \ n", str1); else printf ("% s is not input \ n", str1 );}

References: http://zhidao.baidu.com/question/123856313.html

V. Reverse sorting of linked lists

# Include <iostream> using namespace STD; typedef struct node {int data; node * Next;} * lklist; // generate the linked list lklist creatlist (int n) {lklist head by means of end insertion, p, q; int size = sizeof (node); Head = (lklist) malloc (size); P = head; int X; For (INT I = 0; I <N; I ++) {q = (lklist) malloc (size); cout <"input node" <I <"value:"; CIN> X; q-> DATA = x; P-> next = Q; P = Q;} p-> next = NULL; return head ;} // output a linked list in reverse order void printlk (node * l) {lklist p, q; P = q = L;/* P, Q is the two pointers pointing to the header Node */While (p-> next! = NULL) P = p-> next;/* point P to the last node of the key table */while (1) {While (Q-> next! = P) q = Q-> next;/* Ask Q to find the last node to be printed */printf ("% d \ n ", p-> data); P = Q;/* P move one forward */q = L;/* q points to the header node */If (P = L) /* exit after access */break;} // exchange the lklist reverse (lklist h) before and after the element position of the linked list // H is the head pointer of the linked list {lklist P, V1, v2; v2 = H; V1 = NULL; while (V2! = NULL) {P = v2-> next; v2-> next = V1; V1 = V2; v2 = P;} return V1 ;} // swap the positions of elements in the linked list before and after lklist res (lklist h) {lklist S, S1; S = H; H = NULL; while (s) {S1 = s; S = s-> next; S1-> next = H; H = S1;} return h;} void main () {lklist LK = creatlist (5 ); // printlk (lk); // lklist rk = reverse (lk); lklist rk = res (lk); While (rk-> next! = NULL) {cout <rk-> data <"; rk = rk-> next ;}}

References:

1. http://zhidao.baidu.com/question/41056423.html
2. http://lixon2000.blog.163.com/blog/static/996498020061026113420769/

6. Big integer multiplication

void multiply(char* a,char* b,char* c){    int i,j,ca,cb,* s;    ca=strlen(a);    cb=strlen(b);    s=(int*)malloc(sizeof(int)*(ca+cb));    for (i=0;i<ca+cb;i++)        s[i]=0;    for (i=0;i<ca;i++)        for (j=0;j<cb;j++)            s[i+j+1]+=(a[i]-'0')*(b[j]-'0');    for (i=ca+cb-1;i>=0;i--)        if (s[i]>=10)        {            s[i-1]+=s[i]/10;            s[i]%=10;        }    i=0;    while (s[i]==0)        i++;       for (j=0;i<ca+cb;i++,j++)           c[j]=s[i]+'0';    c[j]='\0';    free(s);}

References:

1. http://topic.csdn.net/u/20080203/10/64d519c1-030c-4725-abe4-e4d1061e894c.html
2. http://wenku.baidu.com/view/8ac7c44ffe4733687e21aadd.html
3. http://wenku.baidu.com/view/968c4ba0b0717fd5360cdc71.html

VII. Newton Iteration Method for Finding the root of the equation

#include<stdio.h>float solution(float x){float x1,y,k;do{k=6*x*x-8*x+3;y=2*x*x*x-4*x*x+3*x-6;x1=x-y/k;x=x1;}while(fabs(y)<0.001);return x;}void main(){float x;x=1.5;x=solution(x);printf("%f\n",x);}

References:

1. http://zhidao.baidu.com/question/73178644.html? Fr = qrl & cid = 866 & Index = 4

2. http://zhidao.baidu.com/question/6326922.html? Fr = qrl & cid = 93 & Index = 5 & FR2 = Query

 

It is a classic program to determine whether an integer is a program that multiply the number of input and the number of integers. Sometimes it is difficult to think.

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.