hinduengg 26 Junior Poster in Training

Dear Indrapriya,

Please mark the problem as solved.

hinduengg 26 Junior Poster in Training

Explain a little more about your problem. Post your effort. Its then you will get help.

hinduengg 26 Junior Poster in Training

Is your file location correct? - "/etc/rc.d/rc.local"

hinduengg 26 Junior Poster in Training

You should try out functions specified in <graphics.h> for creating your assignment.
Scan through the functions specified in them .
I use Turbo C for compiling my programs.
You can use other IDEs like Dev C++ because its considered obsolete but not yet for me!

hinduengg 26 Junior Poster in Training

One thing which is very important is that you need to
input your number on screen through keyboard blindly
without computer prompting you

In a nutshell:
Just enter your number once
and then press enter key

You will have your result!

hinduengg 26 Junior Poster in Training

May be this could fix your problem , run it .
I tried it worked, I cant figure out any other alternate way to it in C

#include<graphics.h>
#include<conio.h>
#include<stdio.h>

int main()
{
int ip;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
cscanf("%d",&ip);
getch();
printf("Input Output \n");
printf("%d    %d",ip , ip);
getch();
return 0;
}
hinduengg 26 Junior Poster in Training

wonderful

hinduengg 26 Junior Poster in Training

Thank you very very much . :)
May God bless you all.

Regards,
hinduengg

hinduengg 26 Junior Poster in Training

Please help me find the sine series .
My program is:

#include<stdio.h>
#include<conio.h>
#include<math.h>
float facto(int a);
int main()

{
     int n,g,k,y;
     y=1;
     float s=0.0;
     float f=0.0;
     float l =0.0;
     float x;
     int t=0;
     
       printf(" limit is \n");
     scanf("%d",&n);
       
       printf(" no. is \n");
        scanf("%d",&x);
     x=3.14*(x/180.0);
     
        while(y<(n+1))
       {     g=y;
             if(g%2==0)
              t=-1;
              else
              t=1;
             k=2*g;
             l = facto(g+1);
            f=(pow(x,(g+1))/l)*(t);
            s = s+f;
            y+=2;
          }  
       
          printf("\n sum is %d",s);
          system("pause");
          return 0;
          }
 float facto(int c)
{     int d=1;
       float fact = 1.0;
       while(d<(c+1))
       {
       fact=fact*d;
       d++;}
    return(fact);
}

I am unable to get the correct thing.

For instance , if I gave limit 2 and no. as 34 or any other no. , the output is always 0.
I cant understand this , what is my mistake?

PLEASE help me find it out!:(

Thanks in advance,
hinduengg

hinduengg 26 Junior Poster in Training

after this you should input the elements into the array like this:

cin>>n;
int * y=new int [n];
for(int z=0;z<=n-1;z++)
{
   cout<<"element please"<<endl;
cin>>y[z];
}

this is a loop for inputting the user defined values into you 'y' array.
I think it that way.
May it help you.

hinduengg 26 Junior Poster in Training

Perhaps you should try this like this-
char * ret=new char [n];

for a one dimension array

hinduengg 26 Junior Poster in Training

Yes please tell what exactly you wish to know?
Is it concatenation of 2 nos or two strings?

hinduengg 26 Junior Poster in Training

Could you please tell me what does this statement does
matrix[j]=rand()%2;

check your loop working

Besides you are yourself returning matrix[0][0]; so please try with a[j] in the j's loop

Regards,
hinduengg

hinduengg 26 Junior Poster in Training

At the site you must check out the Languages section of the index.

hinduengg 26 Junior Poster in Training

You must read this for pointers-http://www.eternallyconfuzzled.com

I think that you might be unable to access the value stored in the returned memory address , so you could point to that memory address to get the value for getting the things right :)

hinduengg 26 Junior Poster in Training

To Lerner ,

The code posted by you is not giving the output that I long for now.

Perhaps now I should end this discussion for no concrete thing has been achieved I will show my professor what I have done . See you all in my next new topic This thread is perhaps too long. My original code could not be made but I tried my best.

Thanks to each one of you,
hinduengg

hinduengg 26 Junior Poster in Training

Dump the loops, what you need is a recursive algorithm which would work for arbitrary lengths of arrays. One of the way is using 'Heap Permute'. Here is a sample program which you can easily adapt to use with C style strings:

// Untested

const int SIZE = 4;
static int counter = 1;

void swap(int arr[], int one, int two)
{
    int tmp = arr[one];
    arr[one] = arr[two];
    arr[two] = tmp;
}

void print(int arr[])
{
    for(int i = 0; i < SIZE; ++i)
    {
        cout << arr[i] << "  ";
    }
    cout << " ------->  " << counter++;
    putchar('\n');
}

void permute(int arr[], int size)
{
    if(size == 1)
    {
        print(arr);
    }
    else
    {
        for(int i = 0; i < size; ++i)
        {
            permute(arr, size - 1);
            if(size % 2 == 1)
                swap(arr, 0, size - 1);
            else
                swap(arr, i, size - 1);
        }
    }
}

int main()
{
    int myArr[SIZE] = {1, 2, 3, 4};
    permute(myArr, SIZE);
    cin.get();
}

I am wondering whether I am right or not, is it that one can call the function from its own code block , because I have been taught that one can call a function from any other function or from main().

I did not understand

void permute(int arr[], int size)
{
    if(size == 1)
    {
        print(arr);
    }
    else
    {
        for(int i = 0; i < size; ++i)
        {
            permute(arr, size - 1);// function call from within the same function:(
            if(size % 2 == 1)
                swap(arr, 0, size - 1);
            else
                swap(arr, i, size - 1);
        }
    }
}
hinduengg 26 Junior Poster in Training

Wow Lerner :icon_cheesygrin:your solution is really superb, awesome , mind blowing . Now I would make the whole code and then post it. I hope that although it is little lengthy(for 7 loops) but still the code is very very easily undestood by me !:)

Thank you so much,
hinduengg

hinduengg 26 Junior Poster in Training

To Lerner,

I tried your programs , they give the same output as my original one posted before yours. Could you help in atleast in hinting how to form the third loop to control per[3] if not the code for it .

I am trying this problem for the last 1 week but no concrete solution has come up my way to solve the problem . I am not saying that nobody helped but the solution yet is far away from me .

To JRM

could you post the code that can print atleast 6 combinations so that i can understand the problem better . Never mind if its wrong. There will be something to look forward to .

Thanking you both,
hinduengg

hinduengg 26 Junior Poster in Training

Is it a monthly competition , if so what does the winner receive ?
I did not read about this in the FAQ. Is this type of competition an integral part of Daniweb?

:) Please tell,
hinduengg

hinduengg 26 Junior Poster in Training

this is my code but you would need to change the headers as per new rules of C++

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
int main()
{
  char a[100];
char b[100];
cout<<"enter sentence"<<endl;
cin.getline(a,100);
strcpy(b,' ');
strcat(b,a);
strcpy(a,b);
int x,y,len,k;
len=strlen(a);
k=len;
for(x=len-1;x>=0;x--)
{
  if(a[x]==' ')
   { 
      for(y=x+1;y<=k;y++)
        cout<<a[y];
           k=x;
    }
  }
return 0;
}

if input is -I AM BEST
OUTPUT IS-BEST AM I

hinduengg 26 Junior Poster in Training

I got that point but the code at present does not give 6 permutations as needed this means we neend to use 3 nested loops inside x = 0 to len-1 . Okay I will try it tomorrow for right now it is 12:29 am at my place . I would post the thing that I have got here to clear my doubts.

Thank you so much,
hinduengg

hinduengg 26 Junior Poster in Training

Thank you, thank you Lerner . I will try the program on my compiler to see what is its output. Or please could you tell me what is the difference between the last code of yours and mine .

What is its output? please tell . I tried mine one for atleast 1 hour but did not anything useful. May be your code would rectify me. Please sir . tell me the difference coz I am confused!

What is meant by exclusionary check - that is not needed but why so?
Please help.:)

hinduengg 26 Junior Poster in Training

I am not able to swap the values because I cannot hold th position of y in the 'if' loop.
temp=a[y];
a[y]=a[y++];
a[y++]=temp;

hinduengg 26 Junior Poster in Training

Thank you JRM!

This is the code that gives me only three permutations of string " joy"
I am not able to swap the values because I cannot hold th position of y in the 'if' loop.

temp=a[x];
a[x]=a[x++];
a[x++]=temp;

HELP ME!

#include<iostream.h>
#include<conio.h>  // these headers need to be modified as per new rules in c++
#include<string.h>
int main()
{
   char a[100];
   char per[100];
   cout<<" word";
   cin.get(a,100);
    stcpy(per,a);
  
int l=strlen(per);
for(int x=0;x<l;x++)
 for(int y=0;y<l;y++)
 {
   if(x!=y)
  cout<<per[y];
  }
  cout<<per[x]<<endl;
}
getchar();
return 0;
}

Help needed in getting hold of different ( index )values of x so that I could swap them up to print 6 combinations instead of 3 .

if you just print per[x]in if loop you will get
oy// 1,2
jy //0,2
jo //0,1
The current output is
oyj
jyo
joy

and my output greatly requires
012
021
102
120
210
201

With lots of hope,
hinduengg

hinduengg 26 Junior Poster in Training

What is meant by mechanical random shell game?. I did not understand this hint , please enlighten me.:)

Thank you,
hinduengg

hinduengg 26 Junior Poster in Training

Did you try swapping in nested loop ?:)

hinduengg 26 Junior Poster in Training

if n=1128(int type)
use this-

while(n>0)
{
  digit=n%10;    //extract individual digit to use 
  cout<<digit<<endl   //or do any operation on it
  n=n/10;   //reducing the n by 10 so that it finally turns to    (0.something)
}

I hope it works:)

hinduengg 26 Junior Poster in Training

you mean that you got the output with a code
do i need 1 nested loop and nothing more complication

hinduengg 26 Junior Poster in Training

WOW! Thank you Lerner, JRM , Bench .

You are great for you removed such an important doubt. I had been confused about this but now its pretty clear to me and perhaps in my code thats why its prints elements of char array each time the loop of x runs so that at the end of 'for' loop we get the modified char array printed till the null charecter is reached at the end of 'for' loop.

Super duper!

Thankyou JRM for the advice but the transfer thing is not quite possible . Never mind in a year or two I would be doing software engineering , my dream . I would now not stretch the thing too far . The program is right now my priority .

I am in struggle with the working code, I would post the new thing when its ready , I am trying Lerner's method instead of plain swapping of the letters.:)

Thank you,
hinduengg

hinduengg 26 Junior Poster in Training

Thank you for permu[3]='\0' answer.
It means that if an array has 100 then we can utilise space upto 99 charecters - o to 99 and then '\0'
Nichito puts and cout both do the same function in C++ atleast in my program . I would like to request you to tell whether this statement

cout<<per<<endl; OR puts(per) in your code print charecters or the modified word on new lines . I think it prints changed words but how does it happen is a mystery.

Please solve the trivial query
Any help would be appreciated

From.
hinduengg:)

hinduengg 26 Junior Poster in Training

Well its not that my code is wrong , actually I use turbo C++ which is surely outdated in today's world. It still accepts the old rules and syntaxes applied in C++ , which have been changed since 1998. I openly admit that our college still loves old setups .

But no use of complaining to the authorities , they will never listen . Perhaps after my intermediate I would adopt the newer modified version of C++.
I will have to first learn the old setup for exams and perhaps the new one for software engineering.

hinduengg 26 Junior Poster in Training

I understood Lerner ,it means you are interchanging the positions by all combinations . This is the thing which I did earlier but did not find much success by drawing the array with letters in different positions and getting combinations.
I need to develop code for accessing these positions with for loops in the given series.
I thought swapping would be enough, but here we are also trying to swap between 2 consecutive positions of the permuted word to get the position combinations. Is not it?

The working code that was in #9 is working code but I need to develop original code with my effort and your help, if I just mug up the solution , what is the use of it .

Right?:)

I am on the solution with a positve approach now . With your sincere help and my effort I will make it through. I will not lose paitence

Bear with me ,
hinduengg

hinduengg 26 Junior Poster in Training

I wish to ask how can permu and input has 4 size when dol is 0 ,1, 2 ,'\0'
because this would mean that it can fit in 4 charecters with null .
then null charecter should be at position 4 i.e permu[4]='\0';
Please correct if I am wrong?

I will take some more time understanding the explaination given by Lerner.

hinduengg 26 Junior Poster in Training

To JRM,
line 26 prints the string with alterations automatically regarding that and that s why have a question too with thinking sign!

hinduengg 26 Junior Poster in Training

and I have to design for seven character containing string then sholud I use 7 loops? I am unable to understand. Please give advice. The code is in C++ and I tried Nichito's program my way it gave me the above o/p in my previous post.

Thank you,
hinduengg

hinduengg 26 Junior Poster in Training

I did not understand the first part of your post , I am aiming the second part . why do you use permu[3] then put a null charecter
at position 3?

hinduengg 26 Junior Poster in Training

You may opt for Java because its a new language that is yet to be developed instead of C or C++ . The latter have become full fledged,vast. There are thousands of sites which use java applets. Java is currently very popular , much more than the others.

For me Java was really easy to learn than C++. It had so nice sorting techniques , so lucid for anyone in my small view.:)

hinduengg 26 Junior Poster in Training

yes perfectly true I did not run the code but I had the statements in mind quite well but not the order . I am sorry.

It is first extract the digit by mod method then use wherever you wish to and then divide the number by 10 to reduce it to zero.

hinduengg 26 Junior Poster in Training

Thanks for taking pains . The code below gives me 5 permutations
-"old" remains.

#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
int main()
{
char a[100];
char per[100];
char temp;
cout<<"enter the word"<<endl;
gets(a);

strcpy(per,a);
puts(per);
getchar();

for(int y=0;a[y]!='\0';y++)
{
  for(int x=0;per[x]!='\0';x++)
  {   temp=per[x];
   per[x]=per[y];
   per[y]=temp;  //swapping positions
   cout<<per<<endl;
   }
  }
 getch();
return 0;
}

If the given input is-"dol"
then output is :
dol
odl
ldo
dlo
dlo
lod
ldo
ldo


In the above output i have- dol,odl,dlo,ldo,lod but old is missing .

The problem that after 1st loop run the y=1 then when x loop is run
we get - swapped positions of "dlo" then when 2nd time loop of y is run in which y=2 then we would be getting permutations of word-"ldo".

How can I catch "old" permutation and if I am not wrong that puts and cout perform in same manner!:-/

Thank you ,
hinduengg

hinduengg 26 Junior Poster in Training

the method is easy :)

hinduengg 26 Junior Poster in Training

You can extract the no.'s digits by this method :
if n is user's input of int type then

while(n>0)
{
  n=n/10;
  digit=n%10;
  if(digit==4)
   counter++;
 }

Then print the counter that contains the no. of 4's in your inputted number

hinduengg 26 Junior Poster in Training

I am unable to implement the logic suuceesfully .:sad:
I have put in my best efforts but no result ! I can not develop the code and you cannot say that I have not tried. I spent a lot of time using lot of for loops for getting the charecters fitted to the rotating positions. So please gift a little code to end this problem. I tried and if you would ask me "where is my effort?" , I would say that wasting 3 days on this is enough proof plus the codes one which i tried to develop and the other of Vegeseat, which was a little complex.

I attempted the problem several times but could not achieve it.
Besides on the net they use mostly recursion methods which is not taught to us.

So please help !! I really need it.:confused:
Hinduengg

hinduengg 26 Junior Poster in Training

Thank you for the wonderful aid. Now I have got a new direction in the seemingly complicated logic . I would now try once again with the technique although I was thinking the same but could not figure it out clearly . I have been worked up with this for just 2 days . But with the guiding lights I would be able to make it to my goal soon.

Thank you a lot to everyone- WaltP, Killer typo, darkscript,Lerner , Iamwithwee .

hinduengg 26 Junior Poster in Training

char array="food";
You can use delete[]array to clear the memory

hinduengg 26 Junior Poster in Training

this is the code that I actually got while browsing through code snippets

#include<iostream>
#include<cstring>

using namespace std;

void char_permutation(char str[],char append[])
{
  int length = strlen(str);
  if (length)
  {
    for(int i=0;i<length;++i)
    {
      char* str1 = new char[length+1];
      int cnt;
      int cnt2;
      for(cnt=0,cnt2=0; cnt<length; ++cnt,++cnt2)
      {
        if (cnt == i)
        {
          str1[cnt] = str[++cnt2];
          continue; 
        }
        else
          str1[cnt] = str[cnt2];
      }  
      str1[cnt] = '\0';
      
      int alength = strlen(append);
      char* append1 = new char [alength+2];// why adding 2 here
      strncpy(append1,append,alength);
      append1[alength] = str[i];
      append1[alength+1] = '\0';
      
      char_permutation(str1,append1);
      
      delete []str1;
      delete []append1; 
    } 
  }
  else
  {
    cout << append << endl; 
  }  
}


int main()
{
  char str[] = "BUSH";  // shows a little humor
  char append[] = "\0";  

  cout << "Original = " << str << endl;  
  char_permutation(str,append);
    cout << "Done ........" << endl;
    
    cin.get();  // wait
  return 0;
}

Please devote some of your precious time in making me understand this.:( My question is in the code comments , please,please tell the reason for that. Varunthai had understood it but he did not write any grain of logic for me to understand!:(

Till now I have understood that there are 2 strings on which permutation is working but the process of cnt cnt2 ,and statements like - char* append1 = new char [alength+2]; confuse me then.
please help:(

I would appreciate your help greatly

hinduengg

hinduengg 26 Junior Poster in Training

if you show us how far you have gone, it will be easier for us to help you

the concept is still in infancy development , I need your help:
this is so far I have developed the code:

#include<iostream>
int main()
{
  int c,y,m=0;
   int z,fact;
    char a[100];  
 for(y=0;a[y]!='\0';y++)
      c++;
     cout<<"the length"<<c<<endl;
    for(x=1;x<=c;x++)
     {
     fact=1;
     fact=fact*c;
     }
     cout<<"no of permutations"<<fact<<endl;
     for(int w=1;w<=fact;w++)
      for(int y=0;a[y]!='\0';y++)
      {
         m=y+1;
         cout<<a[m];
         }

I am unable to understand what to do to print permutations
and address index of the previous value of the string.

hinduengg 26 Junior Poster in Training

Could you advice the link . I am not allowed to use stl strings its the char array that I need to use and functions related to it.
What I need is just the starting logic should I use for loops.

hinduengg 26 Junior Poster in Training

Hello once again . My teacher has given us the assignment to enter a string a maximum of 7 charecters and permute it.
Then print all of possible permutations . Like if the inputted word is
JAY so Output would be
JAY
AJY
AYJ
JYA
YAJ
YJA


I do not seem to understand how to go about it. Please help.
I wish to know about some initial logic before developing the right code.

Thank you in advance.
hinduengg

hinduengg 26 Junior Poster in Training

Thank you for your aid.

My course does not involve such high level things specially pointers. I dont know why they do not teach Pointers-so essential thing in C++ .
Although its not in course I still study them in detail to get why are syntaxes have their present form, what they mean such as array declarations.
I think they want us to be confused , but Narue gave me the most accurate solution.Thank you for making me understand.
This is my second year in C++ so uptill now, I can understand basically concepts through simple for, if loops. I am yet to start the high level programming or something that really is essential in C++.

Thank you to all.