Thread: Function calling

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    4

    Function calling

    I have a problem with rotating an array and assigning it to different variables. Please help me with this. This is wat i have done. I am a novice and please help me in this.
    Code:
    #include<stdio.h>#include<stdlib.h>
    #include<conio.h>
    #include<math.h>
    
    
    int n[16],a[16],n1[16],n2[16],n3[16],n4[16],n5[16],n6[16],n7[16],n8[16],n9[16],n10[16],n11[16],n12[16],n13[16],n14[16],n15[16],n16[16], c=0;
    int x[16],i,j,k;
    int rotate();
    main()
    {
          printf("Enter the input \n");
          for(i=0;i<16;i++)
          {
                           scanf("%d",&a[i]);
          }
          for(i=0;i<16;i++)
          {
                           printf("%d",a[i]);
          }
          for(i=0;i<16;i++)
          {
                          int p=rotate();
          }
          getch();
    }
    int rotate()
          {
          printf("\nThe array is now rotated by\n");
          scanf("%d",&j);
          for(c=0;c<j;c++)
          {
          while(c<j)
          {
                    k=a[0];
                    for(i=0;i<16;i++)
                    {
                                     a[i]=a[i+1];
                    }
                    a[15]=k;
                    c++;
          }
          }
          printf("Rotated array is\n");
          for(i=0;i<16;i++)
          {
          printf("%d",a[i]);                           
          }
          }

  2. #2
    Registered User
    Join Date
    Jan 2013
    Posts
    4
    Quote Originally Posted by karthik7 View Post
    I have a problem with rotating an array and assigning it to different variables. Please help me with this. This is wat i have done. I am a novice and please help me in this.
    Code:
    #include<stdio.h>#include<stdlib.h>
    #include<conio.h>
    #include<math.h>
    
    
    int n[16],a[16],n1[16],n2[16],n3[16],n4[16],n5[16],n6[16],n7[16],n8[16],n9[16],n10[16],n11[16],n12[16],n13[16],n14[16],n15[16],n16[16], c=0;
    int x[16],i,j,k;
    int rotate();
    main()
    {
          printf("Enter the input \n");
          for(i=0;i<16;i++)
          {
                           scanf("%d",&a[i]);
          }
          for(i=0;i<16;i++)
          {
                           printf("%d",a[i]);
          }
          for(i=0;i<16;i++)
          {
                          int p=rotate();
          }
          getch();
    }
    int rotate()
          {
          printf("\nThe array is now rotated by\n");
          scanf("%d",&j);
          for(c=0;c<j;c++)
          {
          while(c<j)
          {
                    k=a[0];
                    for(i=0;i<16;i++)
                    {
                                     a[i]=a[i+1];
                    }
                    a[15]=k;
                    c++;
          }
          }
          printf("Rotated array is\n");
          for(i=0;i<16;i++)
          {
          printf("%d",a[i]);                           
          }
          }
    I have got what was wrong with the program. Now i need to store the obtained results and carry on a bit wise and operation. Can anyone help me out with this?? Please!! its an emergency!!

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    How To Ask Questions The Smart Way

    I personally have no idea what you want to achieve.

    Bye, Andreas

  4. #4
    Registered User
    Join Date
    Jan 2013
    Posts
    4
    What I am trying to do here is rotate the array of binary number I input and save the rotated output after each rotation. Then, I want to perform the autocorrelation of the obtained set of numbers. Can u please help me now? I have to submit the code by tomorrow..

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    You need three operations to do a rotation: >> and | and <<. You shift one way by some number of bits and then shift the other way. The pipe operator can glue together your result. Congratulations, you have done 1 bit-wise rotation. You can use the tutorials on the main site to learn this in detail. Come back, with code closer to your actual goal, if you need further help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-23-2012, 02:37 PM
  2. Replies: 15
    Last Post: 06-09-2009, 02:19 AM
  3. Calling function a function to do fopen
    By fanoliv in forum C Programming
    Replies: 1
    Last Post: 06-19-2006, 01:44 PM
  4. Calling Cdocument function in Cview function
    By RancidWannaRiot in forum Windows Programming
    Replies: 5
    Last Post: 09-22-2005, 12:09 PM
  5. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 05:32 PM