Write a C program to do the following: Your program should define three arrays s
ID: 3846216 • Letter: W
Question
Write a C program to do the following:
Your program should define three arrays such that Array1 has eight values: $01, $02, $03, $04, $05, $06, $07, $08 and Array2 has eight values: $11, $12, $13, $14, $15, $16, $17, $18, and Array3 has eight bytes reserved. The program reads DIP switches, then, does the followings:
1. If the readings are exactly %00001001 = $09, then, it will turn on LED3 and LED0, and copy the data from Array1 to Array3; after copying data, your program is done.
2. If the readings are exactly %10010000 = $90, then, it will turn on LED7 and LED4, and copy the data from Array2 to Array3; after copying data, your program is done.
3. If the readings are neither $09 nor $90, then, turn on all LEDs, and go back to read DIP switches repeatedly until one of the two correct readings above is available.
Explanation / Answer
#include <stdio.h>
void copyArrays(int[],int[],int);
int main()
{
int size=8;
int ar1[]={1,2,3,4,5,6,7,8},ar2[]={11,12,13,14,15,16,17,18},ar3[size];
int dipSwitch;
scanf("%d",&dipSwitch);
while(1)
{
if(dipSwitch%9==9)
{
//dipSwitch%00001001
printf("turn on LED3 and LED0 ");
copyArrays(ar1,ar3,size);
break;
}
else if(dipSwitch%144==90)
{
////dipSwitch%10010000
printf("turn on LED7 and LED4 ");
copyArrays(ar2,ar3,size);
break;
}
else
{
//neither $09 nor $90
printf("turn on All LEDs ");
}
scanf("%d",&dipSwitch);
}
return 0;
}
void copyArrays(int *ar1,int *ar2,int size)
{
int i;
for(i=0;i<size;i++)
{
ar2[i] = ar1[i];
}
}
Thankyou.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.