Last active
June 21, 2019 20:06
-
-
Save adi0603/b4c16624b7a3303e9ce75759036d9637 to your computer and use it in GitHub Desktop.
Week 3 Code - Uber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 ',' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clever hack with the above code, good solution all in all, try reducing the complexity of the code a bit.