Automatic generation of simple arithmetic C language programs

Source: Internet
Author: User

The program is found in the blog park, the specific person who found a long time not found, unable to provide its original link. Because of their own writing is too simple, and some features can not be implemented temporarily, so I found a to deal with the work, hope to forgive. In the source code of this program I changed a wrong place, the source code has such a random number generator initialization function statement: "Srand ((unsigned) time (NULL))". The Srand function is the initialization function of the random number generator. But the correct wording should be: srand (unsigned (Time (NULL))), in order to prevent each repetition of random numbers, often using system time to initialize, that is, using the time function to obtain the system times, its return value is from 00:00:00 GMT, January 1, 1970 to the current number of seconds, and then convert the time_t data into (unsigned) type and then to the Srand function, namely: Srand ((unsigned) time (&t)); There is also a regular usage that does not need to define the time_t t variable, namely: Srand ((unsigned) time (NULL)); Pass in a null pointer directly, because your program often does not require parameters to obtain the T data. So in the source he did not define the required time_t t variable, causing the program to not run. The following code is changed:

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

int count_s ();
void over ();

void Main ()
{
int i;
printf ("\n\t\t\t | | Welcome to Primary arithmetic System | | \ n ");
printf ("\n\t\t\t1 begins to do the title \ n");
printf ("\n\t\t\t2 exit \ n");
printf ("\n\t Please enter your choice: \ n");
scanf ("%d", &i);
if (i==1) {
count_s ();
}
else if (i==2)
{
Over ();
}else{
printf ("\n\t input error, please re-enter: d%", i);
Return
}
}

void Over ()
{
printf ("\n\t\t Welcome to use again, thank you!" ");
}

int count_s ()
{
int i=0;
int n=0;
int x=0;
int t;
Char A;
int B, C;
float result;
printf ("/****** Please enter the number of questions to be given: \ n");
scanf ("%d", &n);
Srand ((unsigned) time (NULL));
while (X<n)
{
A = rand ()% 4;
b = rand ()% 100;
c = rand ()% 100;
Switch (t)
{
Case 0:
printf ("%d +%d = \ n", B, c);
Break
Case 1:
printf ("%d-%d = \ n", B, c);
Break
Case 2:
printf ("%d *%d = \ n", B, c);
Break
Case 3:
printf ("%d/%d = \ n", B, c);
Break
}

i++;
while (i>=n)
{
printf ("\n\t total of%d questions \ n", i);
printf ("\n\t\t continue? [ Y/n]\n ");
Fflush (stdin);
scanf ("%c", &a);
if (a== ' Y ' | | a== ' y ')
{
printf ("/***** Please enter the number of questions to be given \ n");
scanf ("%d", &n);
i=0;
Break
}
printf ("Welcome to use again!") \ n ");
Fflush (stdin);
GetChar ();
return 0;
}
}
}

If there is anything wrong, please advise.

Automatic generation of simple arithmetic C language programs

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.