The CE Coding Challange

Discussion in 'Computer Science | IT | Networking' started by Sanyam Khurana, Sep 7, 2013.

  1. Sanyam Khurana

    Engineering Discipline:
    Computer Science
    I couldn't find it how to do it, first I though it to have a class but then realised that it has to be in C. Very nice buddy, this idea didn't strike my mind, one function calling another one, and it's not recursion actually.

    Ok, here's some more questions !

    Write output of the below mentioned code fragment.

    Code:
    #define swap1(a,b) a=a+b;b=a-b;a=a-b;
    main()
    {
    int x=5,y=10;
    swap1(x,y);
    printf("%d %d\n",x,y);
    swap2(x,y);
    printf("%d %d\n",x,y);
    }
    int swap2(int a,int b)
    { int temp;
    temp=a;
    b=a;
    a=temp;
    return 1 ;
    }
    
    Write output with explanation

    Code:
    void main()
    {
    static int i=5;
    if(--i)
    {
    main();
    printf("%d ",i);
    }
    getch();
    }
    
     
    #141
  2. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science
    Swap2 procedure is wrong... still, if we correct it, we'll get same answer printed on screen i.e. 10 5
    1st case we aren't defining new variables a and b hence x and y replace the a and b in 1st statement and the values get swapped to 10 and 5
    But, int second case the new values of x and y i.e 10 5 are passed which are stored in new variables a and b whose scope is only inside the swap2 block! Hence the values of a and b are swapped but not x and y hence again 10 5 is printed

    Pretty easy! only 1 point to remember... the control of program is always returned back to calling function after execution of the function! The if condition stands true for 4 times hence main is called 4 times.
    after the 4th call of main() the condition goes false hence the control is returned to the 4th main() and printf() is executed and it prints the value 0 (since value is decremented in condition check and finally becomes zero)
    after the execution of 4th main the control is returned to the 3rd main() as this was the calling function for main() and again it prints the value 0
    this goes on until we reach 1st main() which is parent of all and after execution of this the program stops with the output

    0 0 0 0
     
    #142
  3. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science
    sad. was getting bored so painted a pic to explain the second code :p
    I don't know how much it explains though!
     
    #143
  4. Gaurav v. Deshmukh

    Gaurav v. Deshmukh Apprentice

    Engineering Discipline:
    Computer Science
    Decypher

    Alice and Bob are being held at Azkaban(Prison). They want to escape and join Dumbledore's Army.
    Alice wants to tell Bob about the details of the plan but wants to keep their escape plan from Dementors(the guards).
    So Alice encrypts the message before passing the chits to Bob's cell.
    However Bob was careless and he disposed the chits in his cell's waste paper bin.
    The clever Dementor found the chits but couldn't make out what they said.
    So he hired a computer programmer to decode the message for him. Please help the Dementor to decypher the message.

    The code key that Alice used for this simple coding is a one for one character substitution based upon a single arithmetic
    manipulation of the printable portion of the ASCII character set.

    INPUT
    The Encrypted message in a single line. The maximum number of charaters in a message is 100.
    (DO NOT PRINT ANY PROMPT MESSAGE TO ENTER THE ENCRYPTED MESSAGE.)

    OUTPUT
    The decrypted message in a single line. (Do not print any other message other than the decrypted message.)

    SAMPLE INPUT 1
    [YHUZMVYT'[V'HUPTHN\Z'MVYT3

    SAMPLE OUTPUT 1
    TRANSFORM TO ANIMAGUS FORM,

    SAMPLE INPUT 2
    HUK'LZJHWL'^OLU'[OL`'IYPUN'MVVK5

    SAMPLE OUTPUT 2
    AND ESCAPE WHEN THEY BRING FOOD.
     
    #144
  5. rahul69

    rahul69 Ace

    Engineering Discipline:
    IT
    Easy enough!
    Here's the solution:
    Code:
    #include<iostream>
    #define max 100
    using namespace std;
    main()
    {
    int i;      
    char a[max];
    cin>>a;
    for(i=0;a[i]!='\0';i++)
    a[i]-=7;
    cout<<a;
    }
    
    
     
    #145
  6. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science
    this was asked in aspirations exam today :p
     
    #146
  7. Sanyam Khurana

    Engineering Discipline:
    Computer Science
    Give the output with explanation :

    Code:
    void main()
    {
    int i=1,j=2;
    switch(i)
    {
    case 1: printf("GOOD");
    break;
    case j: printf("BAD");
    break;
    }
    getch();
    }

    Write a function ``replace'' which takes a pointer to a string as a parameter, which replaces all spaces in that string by minus '-' signs, and delivers the number of spaces it replaced.
    Thus

    Code:
    char *cat = "The cat sat";
    n = replace( cat );
    should set
    cat to "The-cat-sat"
    and
    n to 2.
     
    #147
  8. vaibhav bhanawat

    vaibhav bhanawat Apprentice

    Engineering Discipline:
    Computer Science
    if i want to convert C code into setup file than what should i do
    C code convert into software .....
    that converted setup we can installed in any PC
     
    #148
  9. Aadit Kapoor

    Aadit Kapoor Apprentice

    Engineering Discipline:
    Computer Science
    You can use visual studio to convert a project into an installer.
     
    #149
  10. Aadit Kapoor

    Aadit Kapoor Apprentice

    Engineering Discipline:
    Computer Science
    Code:
    void Forgot_code(struct inventory *v2)
    {
        signed int x;
        printf("Forgot your password started!\n");
        while(1)
    {
        printf("Type this captcha to begin\n");
        printf("Captcha :  2x + 12 = 3x + 23\t Find x!");
        scanf("%d",&x);
        if (x == -11)
        {
            struct inventory *size_for_read_check_info =(struct inventory*)malloc(sizeof(struct inventory *));
            printf("Changing unlock code to the default unlock code\n");
            size_for_read_check_info->unlock_code = 1212;
            printf("%d\n",size_for_read_check_info->unlock_code );
            Read_Check_information(&size_for_read_check_info);
            break;
        }
        else
        {
            printf("Try again!\n");
        }
    }   
    

    Code:
    void Read_Check_information(struct inventory *v3)
    {
        char check_name[32];
        int check_value;
        int check_code;
        printf("Enter your name:\n");
        scanf("%s",&check_name);
        printf("Input your UNLOCK LOCK CODE (type '203' to reset!\n");
        scanf("%d",&check_code);
        if (strcmp(check_name,v3->name_of_owner) == 0 && check_code == v3->unlock_code)
        {
            printf("Welcome!\n");
    
        }
        else if (check_code == 203)
        {
            struct inventory *size_for_forgot_code = (struct inventory *)malloc(sizeof(struct inventory *));
            Forgot_code(&size_for_forgot_code);
            free(size_for_forgot_code);
        }
        else
        {
            system("clear");
            printf("Error 444!\n");
            exit(0);
        }
    
    }

    In the forgot_code function the size_for_check_info unlock code is changing to 1212 but why my Read_Check_information not changing the unlock code.
     
    #150
  11. Aadit Kapoor

    Aadit Kapoor Apprentice

    Engineering Discipline:
    Computer Science
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define MAX 100
    
    void Start_Processing()
    {
        char dot  = '.';
        int i;
        printf("Storing password");
        for (i=0;i<10;i++)
        {
            printf("%c",dot);
            Sleep(1000);
        }
    }
    void Display_password(char pass_d[MAX])
    {
        printf("Your password is %s\n",pass_d);
    }
    void getpassword(char pass[MAX])
    {
        int num_of_char;
        printf("How many characters are there in your password?\n");
        scanf("%d",&num_of_char);
    
        int i;
        printf("Enter your desired password:\n");
        for (i=0;i<num_of_char;i++)
        {
            pass[i] = getch();
            printf("*" );
        }
    
        Start_Processing();
    
        Display_password(pass);
    }
    main()
    {
        char password[MAX];
    
        getpassword(password);
    
    }



    A simple password program.
    Complied with gcc
    any suggestions please post!
     
    #151
  12. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science
    Write a program to find longest alphabatecial ordered substring of a given string

    Ex given string is "abcdabf"
    Longest substring is "abcd"

    Ex2 S-"abadghacr"
    Ans-adgh
    In case of ties
    Print the first one

    Ex3-S-"abcbcd"
    Ans-abc
     
    #152
  13. Sanyam Khurana

    Engineering Discipline:
    Computer Science
    Write the output of the below mentioned code fragment.

    Code:
    void main()
    {
    static char s[] = "Hello!";
    printf("%d\n", *(s+strlen(s)));
    getch();
    }
    Assume all the necessary header files included.
     
    #153
  14. Aadit Kapoor

    Aadit Kapoor Apprentice

    Engineering Discipline:
    Computer Science
    Can someone explain 2 dimensional and 3 dimensional arrays in c?
     
    #154
  15. Aadit Kapoor

    Aadit Kapoor Apprentice

    Engineering Discipline:
    Computer Science
    OUTPUT : GOOD
    because int i = 1
    case 1: i is already one then it will print GOOD.
     
    #155
  16. Aadit Kapoor

    Aadit Kapoor Apprentice

    Engineering Discipline:
    Computer Science
    OH SORRY!
    OUPUT IS ERROR!
    because case accepts only chars,strings,integers BUT NO variable.
     
    #156
  17. Sanyam Khurana

    Engineering Discipline:
    Computer Science
    Why is this thread dead :eek::(
    Isn't there anyone to share & try out stuff.. :cry:
     
    #157
  18. Abhishek Rawal

    Moderator

    Engineering Discipline:
    Electronics & Communications
    Okay, here you go then : https://www.bountysource.com/teams/elementary/bounties
    Take a look at bugs we are having, fix it up, upstream the patch, claim your bounty.
    For example this critical plank bug ,fix it & claim the bounty. Good way to earn money & learn something new & challenging.
     
    #158
  19. Sanyam Khurana

    Engineering Discipline:
    Computer Science
    #159
  20. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science
    An array consists of binary number, swap all 0's to the end.
    Example : 100110111101 gives 111111110000
     
    #160

Share This Page