Please help me to develop algorithm


 
Thread Tools Search this Thread
Top Forums Programming Please help me to develop algorithm
# 1  
Old 05-09-2011
Please help me to develop algorithm

Hi guys , in my study book from which I re-learn C is task to generate all possible characters combination from numbers entered by the user. I know this algorithm must use combinatorics to calculate all permutations. Problem is how to implement algortihm.
Code:
// This program reads the four numbers from the user
// and saves them into the array. Once all numbers entered
// program will translate input numbers to letters 
// like we have on phone keys, zero and and one will 
// be translated into the space
// Author: solaris_user
// Date: 08.05.2011

#include <stdio.h>

#define ARRAY_SIZE 4

int main(void)

{
    int phone_numbers[ARRAY_SIZE], counter, printer;

    for (counter = 1; counter <= ARRAY_SIZE; counter++) 
     {
        do {        
            printf("Enter %d phone number: ", counter);
            scanf("%d", &phone_numbers[counter]);
            if (phone_numbers[counter] < 0 || phone_numbers[counter] > 9) 
                {
                    printf("Incorrenct data input\n");
                    printf("Please try again\n");
                }
            } while (phone_numbers[counter] < 0 || phone_numbers[counter] > 9);
    }    
    
    for (printer = 1; printer <= counter; printer++) 
    {
        switch(phone_numbers[printer]) 
        {
            case 0: case 1: 
                {
                    printf("<space>\n");
                    break;
                }
            case 2: 
                {
                    printf("abc bac cab\n");
                    break;
                }
            case 3: 
                {
                    printf("cde dec ced\n");
                    break;
                }
           ....
        }
    }
        
    return 0;
}

Author says I must have four nested loops. So as a beginner I must ask for help from experienced programmers.

Thanks for reading and for your time Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I would like to have some exercises to develop my skills

Hi , I would like to do some exercises/scripts in order to develop my skills in shell scripts, can someone pass me some links/suggestions where i can find this? Thanks a lot :) (3 Replies)
Discussion started by: prpkrk
3 Replies

2. Shell Programming and Scripting

Please help me to develop this script for autosys job

:wall:Hi All, I want to build script to force start the list of child jobs under a box. I prepared this below script, but this script need to some bug fix at run time. Please help me to to develop this script. Please let me know if any thing require for this script. Advance thank for all.. ... (3 Replies)
Discussion started by: pradipta_pks
3 Replies

3. Shell Programming and Scripting

Help to Develop a LINUX macro?

Hi Experts, i would like to get your help to do some development to the below linux commands which i run under .cmd file in windows @echo off call f:\linuxutils\grep.exe "T11" f:\blocked_ranges\dump3.txt|f:\linuxutils\grep.exe ",9647800"|f:\linuxutils\grep.exe... (3 Replies)
Discussion started by: mustafa.abdulsa
3 Replies

4. UNIX for Dummies Questions & Answers

Help to develop a new application

Hi all, I am a beginner in advanced unix and just i finished my course in that so now I want to develop an application using advanced unix concepts and middleware technology, so that i can gain an initial working knowledge. Kindly give me a suggestion of what i can develop. (5 Replies)
Discussion started by: jimmyuk
5 Replies

5. HP-UX

how could find HP UX application develop library

if I would like to develop application on HP UX ,where can I serarch the library and API ,like develop windows application with MSDN thanks (1 Reply)
Discussion started by: alert0919
1 Replies

6. UNIX for Dummies Questions & Answers

How to develop C program using UNIX command

hai friend, I am new to linux... I have to develop C program using unix command and i know the SYSTEM command.. But i need other then SYSTEM comand, plz send me the sample code.... Thank you.. sundar (1 Reply)
Discussion started by: sundar.lsr
1 Replies

7. Shell Programming and Scripting

Develop 2 IPC System Calls

I need to develop 2 IPC system calls. 1) The first one allows sender to send a message to set of receivers in a single call. 2) The second one allows receiver to receives all message that have been sent to it in a single call Please help me in developing this system calls ....atleast how... (1 Reply)
Discussion started by: Anki
1 Replies

8. UNIX for Dummies Questions & Answers

unix develop environment

hi! i am Carlos i study @ UABC (Autonomy University of Baja California)... i have a final project.... i need to make a presentation of the new... unix develop environment... but... i have some problems with that.... could you tell me something to help me? (0 Replies)
Discussion started by: Nx GT-R
0 Replies

9. Shell Programming and Scripting

develop a new kernel

Hi people, I am trying to install a second kernel on my Red Hat 8.0 machine. the existing kernel is 2.4.18 and I am trying to have 2.4.20. I already downloaded the source extracted it run make , make dep and make bzImage . Now when trying to copy the installed kernel image from /usr/src to... (4 Replies)
Discussion started by: bashirpopal
4 Replies
Login or Register to Ask a Question