初学数据结构

 1 typedef enum{ A, B, C, D } SchoolName;
 2 typedef enum{Female,Male} SexType;
 3 typedef struct
 4 {
 5     char event[3];
 6     SexType sex;
 7     SchoolName school;
 8     int score;
 9 }Component;
10 typedef struct{
11     int MaleSum;
12     int FemaleSum;
13     int TotalSum;
14 }Sum;
15 Sum SumScore(SchoolName sn, Component a [], int n)
16 {
17     Sum temp;
18     temp.MaleSum = 0;
19     temp.FemaleSum = 0;
20     temp.TotalSum = 0;
21     int i;
22     for (i = 0; i < n; i++)
23     {
24         if (a[i].school = sn)
25         {
26             if (a[i].sex == Male)
27                 temp.MaleSum += a[i].score;
28             if (a[i].sex == Female)
29                 temp.FemaleSum += a[i].score;
30         }
31     }
32     temp.TotalSum = temp.MaleSum + temp.FemaleSum;
33     return temp;
34 }

 

#include<iostream>
#include<cstdlib>
using namespace std;
#define MAXINT 65535
#define ArrSize 100
int fun(int i);
int main()
{
    int i, k;
    int a[ArrSize];
    cout << "Enter K:";
    cin >> k;
    if (k > ArrSize - 1)
        exit(0);
    for (i = 0; i <= k; i++)
    {
        if (i == 0)
            a[i] = 1;
        else
        {
            if (2 * i*a[i - 1] > MAXINT)
                exit(0);
            else
                a[i] = 2 * i*a[i - 1];
        }
    }
    for (i = 0; i <= k; i++)
    {
        if (a[i] > MAXINT)
            exit(0);
        else
            cout << a[i] << " ";
    }
    system("pause");
    return 0;
}

 

 1 #include<iostream>
 2 #include<cstdlib>
 3 #define N 10
 4 using namespace std;
 5 double polynomail(int a [], int i, double x, int n);
 6 int main()
 7 {
 8     double x;
 9     int n, i;
10     int a[N];
11     cout << "input x:";
12     cin >> x;
13     cout << "input n:";
14     cin >> n;
15     if (n > N - 1)
16         exit(0);
17     cout << "input every number:";
18     for (i = 0; i <= n; i++)
19         cin >> a[i];
20     cout << "The polynomail value is:" << polynomail(a, n, x, n)<<endl;
21     return 0;
22 }
23 double polynomail(int a [], int i, double x,int n)
24 {
25     if (i > 0)
26         return a[n - i] + polynomail(a, i - 1, x, n)*x;
27     else
28         return a[n];
29 }

 

posted @ 2013-09-29 22:14  herizai007  阅读(236)  评论(0编辑  收藏  举报