First-week pairing programming arithmetic

Source: Internet
Author: User

Project requirements: The program randomly generates arithmetic calculation questions, and after the user fills out the answer to determine the correct answer.

Pair member: Li Qiao

Task assignment: The algorithm thought and the main function adopted by Li Qiao are responsible for.

I am responsible for some code input and results testing.

Roughly divided into two modules: 1. Randomly generated arithmetic calculation questions 2. Determine the correct and correct input answers

The main code is as follows:

1#include <stdio.h>2#include <string.h>3#include <time.h>4#include <stdlib.h>5 intMain ()6 {7       Charstr[]="+-*/";8Srand (Time (0));9       intres[Ten];Ten        for(inti =0; i<=9; i++) One       { A             intA = rand ()% -+1; -             intb = rand ()% -+1; -             intc = rand ()%4; the             if(c==3) -             { -                  while(a%b) A = rand ()% -+1, B = rand ()% -+1;  -             } +printf"%d%c%d\n", a,str[c],b); -             if(c==0) Res[i] = a +b; +             Else if(c==1) Res[i] = A-b; A             Else if(c==2) Res[i] = A *b; at             ElseRes[i] = A/b; -       } -       ints[Ten]; -printf"Please enter an answer separated by a space \ n"); -        for(intI=0; i<=9; i++) -       { inscanf"%d",&s[i]); -       } to        for(intI=0; i<=9; i++) +       { -           if(s[i]!=Res[i]) the           { *printf"question%d is wrong, the correct answer is%d\n", i+1, Res[i]); $            }Panax Notoginseng       } -       return 0; the}

The results of the operation are as follows:

First-week pairing programming arithmetic

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.