C language Exam (1)

Source: Internet
Author: User
Tags greatest common divisor mul sorted by name

College more wonderful, a big time to learn VB, this semester to learn C + +, and then in the first three weeks of school without classes, the teacher said three weeks of C language, every day 9:30~11:30 lectures, except holidays and weekends, the actual lecture time is 12 days * 2 hours, the afternoon is 14:10~5:00, On the computer, but there are nearly three hours of machine time every afternoon. Time so urgent also to test, this morning learned that the exam question is from the following 10 questions out, a lot of ease. The questions are as follows:

1. Calculate and output its results.

2. Find the highest, lowest, and above average numbers of n students in a course.

3. There are 10 integers in 100, sorted from large to small using the Select Sort method.

4. There are n candidates, each candidate has a test number and a total score, if the admission m (n>m), determine the admission fraction, and output the test marks and scores on the score.

5. Using the process to achieve: to find the greatest common divisor of two positive integers.

6. Using the process to achieve: to find the least common multiple of two positive integers.

7. The approximate value of Yi Yuanfang x5+2x3-x2+x+1=0 near 0 is obtained by Newton iterative method.

8. Find the maximum of 3 primes within 1000.

9. Design a simple calculator with + 、-、 *,/, root, factorial, exponent, sine, cosine, tangent, to find the remainder function.

10. Using the text editing software to build a data file with n students ' number, name, department, contact number on external memory. Enter a school number from the keyboard to search for additional information about this person. and sorted by name and output.

After a noon and an afternoon of struggle, solved the first few, the code is as follows:

Gorgeous Split-line ************************************

First question:

#include <stdio.h>
int mul (int n)
{
int num,i;
Num=1;
for (i=1;i<=n;i++)
Num=num*i;
return (NUM);
}
void Main ()
{
int i,sum=0;
for (i=1;i<=10;i++)
Sum+=mul (i);
printf ("The sum is%d\n", sum);
}
}

Improved:

Enter N to calculate the and of the factorial from 1 to N.

#include <stdio.h>
int mul (int n)
{
int num,i;
Num=1;
for (i=1;i<=n;i++)
Num=num*i;
return (NUM);
}
void Main ()
{
int i,n,sum=0;
printf ("Enter the number:\n");
scanf ("%d", &n);
if (n<=0)
printf ("error\n");
Else
{
for (i=1;i<=n;i++)
Sum+=mul (i);
printf ("The sum is%d\n", sum);
}
}

Gorgeous Split-line ************************************

The second question:

#include <stdio.h>
int sort (int a[],int n)
{
int i,j,temp;
for (i=0;i<n;i++)
{
for (j=0;j<=n-i-1;j++)
{
if (a[j]<a[j+1])
{
TEMP=A[J];
A[J]=A[J+1];
A[j+1]=temp;
}
}
}
}
void Main ()
{
int i,k,sum=0,ave,n=4,a[5];//n=5 in the hypothetical title, that is, there are 5 students in the Code n=4
for (i=0;i<=n;i++)
{
printf ("Please enter number%d\n", i);
scanf ("%d", &a[i]);
Sum+=a[i];
}
Sort (a,n);
printf ("Max is%d\n", a[0]);
printf ("Min is%d\n", a[n]);
ave=sum/n;
for (k=0;k<=n&&a[k]>ave;)
k++;
printf ("The number of above average grades is%d\n", K);
}

To be continued ************************************

C language Exam (1)

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.