C Language Exams

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

College is more wonderful, a big time to learnVB, this semester will learnC + +, and then no classes in the first three weeks of school, the teacher speaks for three weeksClanguage, Daily9:30~11: -lectures, except holidays and weekends, the actual lecture time is Adays * *hour, afternoon is -:10~5:xx, but there are almost three hours of time on the machine 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 integers in the range of ten, sorted from large to small using the Select Sort method.

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

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 number of 3 primes within the max .

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

Ten . 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:

Calculate and output its results.

#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:

input N can be obtained from 1 to the N the factorial of the and.

#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:

Find out N the highest, lowest and above average number of students in a single course.

#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];//in the hypothetical questionn=5,that there5Famous students
??? 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 ("%d\n", K);
}

********************************** Gorgeous split-line ************************************

Question three:

there 10 100

#include <stdio.h>
int sort (int a[], int n)
{
??? int i,j,temp;
??? int min;
??? for (i=1;i<=n;i++)
??? {
??????? min=i;
??????? for (j=0;j<=n;j++)
??????? {
??????????? if (A[j]<a[min])
??????????? {
??????????????? min=j;
???????????}
??????????? if (min!=i)
??????????? {
??????????????? temp=a[j];
??????????????? A[j]=a[min];
??????????????? a[min]=temp;
???????????}
???????}
???}
}
Void Main ()
{
int i,k,n=9,a[10];
??? for (i=0;i<=n;i++)
??? {
??????? printf ("Please enter number (<100)%d\n", i);
??????? scanf ("%d", &a[i]);
//??????? if (a[k]<0| | A[K]>100)
//??????????? goto end;
???????}
Sort (a,n);
for (k=0;k<=n;k++)
??? printf ("%4d", A[k]),
??? printf ("\ n");
end:printf ("error\n");
}

********************************** Gorgeous split-line ************************************

Question Fourth:
have a N candidates, each candidate has a test number and a score score, if the admission m person ( n>m ), determine the admission fraction and output the test number and results of the candidate on the score.

#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,m,n=4,a[5];//in the hypothetical questionn=5,that there5Famous students
??? for (i=0;i<=n;i++)
??? {
??????? printf ("Please enter number%d\n", i);
??????? scanf ("%d", &a[i]);
??? }
Sort (a,n);
printf ("Please enter number m \ n");
scanf ("%d", &m);
for (i=0;i<m;i++)
??? printf ("the test number and the results are respectively%d%d\n ", i,a[i]);
}

********************************** Gorgeous split-line ************************************

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

#include <stdio.h>
void Main () {
??? int A, B;
??? int min,max,tmp;
??? printf ("Enter tne number a b:\n");
??? scanf ("%d%d", &a,&b);
??? A>b? (max=a,min=b):(max=b,min=a);
??? while (tmp= (max%min))
??? {
??????? Max=min;
??????? min=tmp;
??? }
??? printf ("GCF is%d\n", min);
}

? ********************************** Gorgeous split-line ************************************

Question sixth:

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

#include <stdio.h>

void Main () {

int A,B,LCM;

int min,max,tmp;

printf ("Enter tne number a b:\n");

scanf ("%d%d", &a,&b);

A>b? (max=a,min=b):(max=b,min=a);

while (tmp= (max%min))

{

Max=min;

min=tmp;

}

Lcm=a*b/min;

printf ("LCM is%d\n", LCM);

}

C Language Exams

Related Article

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.