First Encounter with ACM — Getting Better

Words: 108

Gradually…

I could even write some code that looked pretty complex to me back then…

This is a program that separates odd and even numbers

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<stdio.h>
int main()
{
    int i,k,n;
    scanf("%d",&i);
    int a[i] ;
    for(k=0;k<i;k++)
        {
        scanf("%d",&a[k]);
        }
    for(k=0;k<i;k++)
        {
            for(n=1;n<=a[k];n++)
                {
                if(n%2==1)
                printf("%d ",n);
                }
            printf("\n");
            for(n=1;n<=a[k];n++)
                {
                if(n%2==0)
                printf("%d ",n);
                }
                printf("\n\n");
        }   

    return 0;
}

Sure, looking at it now there’s plenty that could be improved

But… back then… this was already pretty good, okay!

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...