CodeEval Easy Level Challenge Lowercase

CodeEval Easy Level Challenge Lowercase:

Click here to go to this problem.

Description:

For this problem we just need to change upper case letters to lower case. Here i have solved this problem in 4 programming languages c, c++, java, python.


 C:
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */

#include <stdio.h>
int main(int argc, const char * argv[]) {
    FILE *file = fopen(argv[1], "r");
    char line[1024];
    while (fgets(line, 1024, file)) {
        for(register unsigned int i=0; line[i]; ++i){
            if(line[i] >= 'A' && line[i]<='Z') printf("%c", line[i]+32);
            else printf("%c", line[i]);
        }
        printf("\n");
    }
    return 0;
} 

Java:
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */

import java.io.*;
public class Main {
    public static void main (String[] args) throws IOException {
        File file = new File(args[0]);
        BufferedReader buffer = new BufferedReader(new FileReader(file));
        String line;
        while ((line = buffer.readLine()) != null) {
            line = line.trim();
            // Instead of changing case one by one in for loop, we can also change case of whole string in one function call
            /* System.out.println(line.toLowerCase()); */
            for(int i=0; i<line.length(); ++i){
                char c = line.charAt(i);
                if(Character.isUpperCase(c)) System.out.print(Character.toLowerCase(c));
                else System.out.print(c);
            }
            System.out.println();
        }
    }
}

Python (Python 3):
#
# Author: Quickgrid ( Asif Ahmed )
# Site: https://quickgrid.wordpress.com
#

import sys
test_cases = open(sys.argv[1], 'r')
for test in test_cases:
    print(test.lower())

test_cases.close()

CodeEval Easy Level Challenge Odd Numbers

CodeEval Easy Level Challenge Odd Numbers:

Click here to go to this problem.

Description:

For this problem there is no input. We just print odd numbers from 1 to 100. Here I have solved this problem in 4 programming languages c, c++, java, python. Have a look to learn the syntax difference between these.

There are many ways to solve this one. One way to solve can be starting at 1 and keep increment by 2 until we reach 99. Another can be checking if the number is divisible by 2.


 C:
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */

#include <stdio.h>
int main(int argc, const char * argv[]) {
    register unsigned int i = 1;
    for(; i<=99; i+=2) printf("%u\n",i);
    return 0;
}

C++:
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */

#include <iostream>
int main(int argc, const char * argv[]) {
    register unsigned int i = 1;
    for(; i<=99; ++i){
        if(i&1) std::cout << i << "\n";
    }
    return 0;
}

Java:
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */

import java.io.*;
public class Main {
    public static void main (String[] args) throws IOException {
        for(int i=1; i<100; ++i){
            if(i % 2 == 1) System.out.println(i);
        }
    }
}

Python (Python 3):
#
# Author: Quickgrid ( Asif Ahmed )
# Site: https://quickgrid.wordpress.com
#

for i in range(1,100):
    if(i%2):
        print(i)