Skip to content

Instantly share code, notes, and snippets.

@adi0603
Last active June 21, 2019 20:06
Show Gist options
  • Save adi0603/b4c16624b7a3303e9ce75759036d9637 to your computer and use it in GitHub Desktop.
Save adi0603/b4c16624b7a3303e9ce75759036d9637 to your computer and use it in GitHub Desktop.
Week 3 Code - Uber
//
// Created By Aditya Pandey BCA
//
#include <stdio.h>
void displayArray(int ar[],int size); //declaring array printing function
int main(void) {
int size = 5; //giving size of array
int old[size],new[size],j,i;
printf("Enter numbers in array\n");
for ( i = 0; i < size; i++) {
scanf("%d", &old[i]); //taking inputs in array feom user
}
for ( j = 0; j < size; j++)
{
int x=0,prod=1;
while(x<size)
{
if(old[x]!=old[j]) { //checking that the number should not multiply the storing number
prod *= old[x];
}
x++;
}
new[j]=prod; //storing product in new array
}
printf("Old array\n[");
displayArray(old,size); //passing array to function to print
printf("\nNew array\n[");
displayArray(new,size); //passing array to function to print
return 0;
}
void displayArray(int arr[],int size) //function definition taking size because we cannot find size of array here using 'sizeof' operater
{
for(int i = 0; i < size; i++)
{
i!=size-1?(printf("%d,",arr[i])):(printf("%d]",arr[i])); //number should not end with a ','
}
}
@dbc2201
Copy link

dbc2201 commented Jun 21, 2019

void displayArray(int arr[],int size)       //function definition taking size because we cannot find size of array here using 'sizeof' operater 
{
    for(int i = 0; i < size; i++)        
    {
        i!=size-1?(printf("%d,",arr[i])):(printf("%d]",arr[i]));    //number should not end with a ','
    }
}

Clever hack with the above code, good solution all in all, try reducing the complexity of the code a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment