Thread: Help Me ! C

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Help Me ! C


    i want to generate a sequence with the number given from the user.. can you change the code for me? cuz i cant ! THANKS (sorry my bad english)
    code :
    Code:
    #include <stdio.h>
    #include <strings.h>
    
    void sequences(char *seq){
    unsigned int i,j,k,c = 0;
    int size = strlen(seq);
    for(i = 0; i < size; i++){
    for(j = 0; j < size; j++){
    for(k = 0; k < size; k++){
    printf("%d %d %d\n", seq[i],seq[j],seq[k]);
    c++;
    }
        }
      }
      printf("Count>>>> %d\n",c);
    }
    
    int main(){
    char seq[] = {1,2,3,4,5,6,7,8,9,10};
    sequences(seq);
      return 0;
    }
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,367
    Rep Power
    1870
    Please edit your post and put [code][/code] tags around your code.
    Copy again from your code editor so indentation is preserved.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    35
    Rep Power
    1
    //corrected Prog
    1.you have to use string.h not strings
    2.pointer should be accessed like i did.


    #include <stdio.h>
    #include <string.h>

    void sequences(char *seq)
    {
    unsigned int i,j,k,c = 0;
    int size = strlen(seq);
    for(i = 0; i < size; i++)
    {
    for(j = 0; j < size; j++)
    {
    for(k = 0; k < size; k++)
    {
    printf("%d %d %d\n", *(seq+i),*(seq+j),*(seq+k));
    c++;
    }
    }
    }
    printf("Count>>>> %d\n",c);
    }

    int main()
    {
    char seq[] = {1,2,3,4,5,6,7,8,9,10};
    sequences(seq);
    return 0;
    }

    Comments on this post

    • eramit2010 disagrees : *(seq+i) and seq[i] both are same.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    India
    Posts
    95
    Rep Power
    4
    what do you mean by sequence number??

IMN logo majestic logo threadwatch logo seochat tools logo