Skip to content

C Test #13

@zjs1224522500

Description

@zjs1224522500

Count odd and even numbers

#include<stdio.h>
int main()
{
    int i, n;
    int b = 0;
    int c = 0;
    int a[10];
    scanf("%d", &n);
    for(i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for(i = 0; i < n; i++)
    {
        if (a[i] % 2 == 1)
        {
            b++;
        }
        else
        {
            c++;
        }
    }
    printf("%d %d", b, c);
    return 0;
}

Sort

#include<stdio.h>
int main()
{
    int i, j, index, n, temp;
    int a[10];
    scanf("%d", &n);
    for(i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for(i = 0; i < n; i++)
    {
        for(j = n - 1; j > i; j--)
        {
            if(a[j] > a[j - 1])
            {
                temp = a[j];
                a[j] = a[j - 1];
                a[j - 1] = temp;
            }
        }
    }
    printf("%d", a[0]);
    for(i=1; i<n; i++)
    {
        printf(" %d", a[i]);
    }
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions