Arithmetic Advanced Edition

Source: Internet
Author: User

Based on the original arithmetic, the true fractional operation (validation correctness) is supported in addition to integers.

One-out problem avoids repetition

Customizable number of quiz

#include <stdio.h>
#include <stdlib.h>

int main ()
{
int num,i,k;
printf ("Please enter the number of questions:");
scanf ("%d", &num);
float Fa,fb,fc,fd,result;
k=0;
for (i=0; i<num; i++)
{
int Isint1=rand ()%2;
int Isint2=rand ()%2;
if (isint1==0)
{
Fa=rand ()%100+1;
}
Else
{
Fa=rand ()%100+1;
Fb=rand ()%100+1;
if (FA&GT;FB)
FA=FB/FA;
Else
FA=FA/FB;
}
if (isint2==0)
{
Fc=rand ()%100+1;
}
Else
{
Fc=rand ()%100+1;
Fd=rand ()%100+1;
if (FC&GT;FD)
FC=FD/FC;
Else
FC=FC/FD;
}
int op;
Op=rand ()%4;
Switch (OP)
{
Case 0:
{
printf ("%f +%f=", FA,FB);
scanf ("%f", &result);
if (result-(FA+FB) <0.000001)
k++;
Break
}
Case 1:
{
printf ("%f-%f=", FA,FB);
scanf ("%f", &result);
if (result-(FA-FB) <0.000001)
k++;
Break
}
Case 2:
{
printf ("%f *%f=", FA,FB);
scanf ("%f", &result);
if (result-(FA*FB) <0.000001)
k++;
Break
}
Case 3:
{
printf ("%f/%f=", FA,FB);
scanf ("%f", &result);
if (result-(FA/FB) <0.000001)
k++;
Break
}
}
}
printf ("You counted the right%d questions", k);
}

Arithmetic Advanced Edition

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.