This is what I have to code.
Input an array of numbers(any numbers that user inputs from standard input, aka keyboard), remove numbers from array that are not 0 and 1. Thay array should now be bitwise moved with << or >> (again user choses the number of spaces moved and a type of move). After all of that turn that array into a binary number. Max number of elements is defined as a header with #define max_num_el 255.

I have issues with part of code that need me to move elements of array and turning an array into binary number.

Recommended Answers

All 4 Replies

Post the code you have written so that we can see where your "issues" are.

use temporary variable for moving the items and for binary conversion ,you can easily write code ..

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define max_br_el 255

void main (){
    int p,k,j,n,i,temp,r;
    unsigned long a[max_br_el], b[max_br_el];
    while(1){
        printf("\nEnter number of array elements (between 1 i 255)\n");
        scanf("%d", &n);
        if(n>0 && n<=max_br_el){
            for(i=0 ; i<n ; i++){
                printf("Enter %d. elements of array\n", i);
                scanf("%d.", &a[i]);
            }
            /* Removing nums not 0 and 1 */
            for(i=0 , k=0  ; i<n ; i++){
                if(a[i] == 0 || a[i] == 1){
                    a[k] = a[i];
                    k++;
                }
            }
            n=k;
            for(k=0 ; k<n ; k++){
                printf("%d\t" , a[k]);
            }
            /* My try on moving elements manualy (it has to be done with                  << and >> but I don't know how. Whenever I try to use << and                  >> I get element_of_array*2^n (where and n is number of                      spaces that needs to be moved. */
            printf("\n");
            printf("\nEnter for how many spaces you want to move\n");
            scanf("%d", &p);
            for(r=0 ; r<n; r++){
                b[r] = a[k-p];

            }
            printf("\n");
            for(r=0 ; r<n ; r++){
                printf("%d" , b[r]);
            }
        }
        else{
            exit(1);
        }
    }
}

/* This is code so far. I still don't have part about binary conversion made, because I have bigger issues with << and >>. Here I tryed implementing manual moving of elements of array but it didn't work. Thanks for help. */

I'll show the code tonight, and making this question to solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.