C/C++ Coding challenges

Enigma_1

Junior member
  • Feb 5, 2008
    70
    3
    8
    Colombo
    oky onna next challenge eka. C/C++ program code ekak denna date ekak dunnama (year eka 1899 ta wada wadi date ekak) weekday eka mokakda kiyala denna one.
    for an Eg

    Please enter the date (dd-mm-yyyy) : 30-07-2010 - user input eka
    This day is Friday. - Computer response eka .

    :D:D

    okay here is my solution
    Code:
    #include "stdafx.h"
    #include <time.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    char* dayInput =NULL;
    char* temp;
    tm structTime;
    char * days[] = { "Sunday", "Monday","Tuesday", "Wednesday","Thursday", "Friday", "Saturday"};
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        printf("Please enter the date (dd-mm-yyyy) :");
        dayInput =(char*)malloc(11);
        scanf("%s",dayInput);
        temp =(char*)malloc(4);
        structTime.tm_mday = atoi(strncpy(temp,dayInput,2));
        dayInput = dayInput+3;
        structTime.tm_mon = atoi(strncpy(temp,dayInput,2))-1;
        dayInput = dayInput+3;
        structTime.tm_year = atoi(strncpy(temp,dayInput,4))-1900;
        mktime(&structTime);
    
        printf("it is %s.\n",days[structTime.tm_wday]);
        system("pause");
        
        return 0;
    }
    here I have used only tm structure and mktime() function. both of them are defined in the time.h. I have notice that many C/C++ ppl framed to stdio.h,stdlib.h,iostream.h,conio.h.. but guys there are lots of other headers in C runtime. just check them out. I will put my next challenge soon.
    Thanks :D:D:D
     

    Enigma_1

    Junior member
  • Feb 5, 2008
    70
    3
    8
    Colombo
    CoOOoL thread bro(hope u r a bro.. :P ).. keep it up... :yes::yes:

    May I give u an idea..?? why don't you expand this thread to other languages also, like Java, VB and some scripting languages (PHP is my fav.)

    I think it will be great for all the people who stick with different kinds languages.
    :yes::yes::yes::yes::yes::yes:

    And mind you.. it will attract many people (who r doin some sort of programming or IT related studies) towards Elakiri...:nerd::nerd::nerd::nerd:


    It will definitely attract the IT students who desperately look for solutions and clues for their assignment.
    GT will be very grateful to you for new members..;);)

    + rep.. :D:D:D

    Thanks for the post. Its a grt idea machan. But I code only with C/C++ and C#. I knw little bit of VB 6.0 and VB.net. But I don't know PHP,java..... Yes from now on you can use any language. bcoz it doesn't matter what language that you are using. you have to think for that specific logic. But I need your help guzz. Another thing is any one can post a challenge here. So this will be an open thread for every one. if you have any assignments , challenges , just post your questions here.:yes::yes::yes::yes::yes:


     
    Last edited:

    croshanlg

    Member
    Jan 7, 2008
    2,665
    285
    0
    6° 54' N 79° 52' E
    Thanks for the post. Its a grt idea machan. But I code only with C/C++ and C#. I knw little bit of VB 6.0 and VB.net. But I don't know PHP,java..... Yes from now on you can use any language. bcoz it doesn't matter what language that you are using. you have to think for that specific logic. But I need your help guzz. Another thing is any one can post a challenge here. So this will be an open thread for every one. if you have any assignments , challenges , just post your questions here.:yes::yes::yes::yes::yes:


    OK.. gr8..:D... don't worry machan.. I'm sure there will be lots of EK'ians doing different lang's & they will make sure this thread goes on.. :yes:

    I'm little bit busy these days, hoping to post some challenges ASAP.:yes:

    Best of luck for one of the coolest threads in EK.:love:
     
    • Like
    Reactions: koondeGoda

    Enigma_1

    Junior member
  • Feb 5, 2008
    70
    3
    8
    Colombo
    not heavy math.. but image processing and heavy logic.. :yes::yes:

    I didn't do double math for my degree.I did only single maths. AI was there in my IT degree. I did it. So why don't you give us the start. You have the interest on this. We will start from a simple application:D. Then we'll improve it. You have my full support on this. :yes:
     

    Enigma_1

    Junior member
  • Feb 5, 2008
    70
    3
    8
    Colombo
    ok guyss next challenge
    Write a program to show the hexadecimal representation of any given integer.For an example program will look like this


    Please enter the integer value : 5498 - user input
    hexadecimal representation of 5498 is 0x157A.
    - computer out put

    remember this is an open thread for any programming language
    good luck :D:D:D
     

    yrollgayanth

    Member
    Aug 26, 2008
    1,524
    113
    0
    Melbourne, AU
    In java

    Code:
    package integertohex;
    
    import java.io.*;
    
    public class Main {
    
      public static void main(String[] args) throws IOException{
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the decimal number:");
        String hexval_1 = bf.readLine();
        int x = Integer.parseInt(hexval_1);
        String hexval_2 = Integer.toHexString(x);
        System.out.println("Output in hexadecimal: " + hexval_2);
      }
    }

    don't know C++ much
     

    Dileepa.

    Member
    Jul 29, 2010
    153
    11
    0
    In java

    Code:
    package integertohex;
    
    import java.io.*;
    
    public class Main {
    
      public static void main(String[] args) throws IOException{
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the decimal number:");
        String hexval_1 = bf.readLine();
        int x = Integer.parseInt(hexval_1);
        String hexval_2 = Integer.toHexString(x);
        System.out.println("Output in hexadecimal: " + hexval_2);
      }
    }

    don't know C++ much

    ha ha... i think using inbuilt functions are not acceptable.:D