c language Fill in the parts indicated by ► (meaning missing items). /* This program prompts for the colors of three bands of a resistor, and displays the * value of the resistance in kilo-ohms based on a color code */ #include #include /* for pow*/ #include /* for toupper*/ #include /* for strlen*/ #define NOT_FOUND -1 /* constants */ #define SUB_1 10 #define SUB_2 7 int search(const char [][SUB_2], const char [], int); int main(void){ char reply, /* user reply*/ char_left; /* character left in the input stream*/ int i; int counter; /* counters */ int value; /* subscript of target found in list*/ double answer = 0.0; /* value of resistor in kilo-ohms*/ int no_error = 1; /* denotes no error */ /* initializing the array*/ char COLOR_CODES[SUB_1][SUB_2] = {"black", "brown", "red", "orange","yellow", "green", "blue", "violet", "gray", "white"}; char target[SUB_2]; /* target string array*/ do{ printf("Enter the colors of the resistor's three bands, beginning with\n"); printf("the band nearest the end. Type the colors in lowercase letters only, "); printf("NO CAPS.\n\n"); for(counter = 1; ►; counter++) { printf("Band %d => ", counter); scanf("%s", target); value = search(►, ►, SUB_1); /* searches for string*/ if(value != NOT_FOUND) { switch(counter){ case 1: answer = value * ►; break; case 2: answer += value; break; case 3 if (value>3) answer+=pow(►); else for(i = 0; ►; i++) answer /= 10; } } else no error = 0; /* if string not found*/ } if (►) printf("Resistance value: %.3f kilo-ohms\n\n", answer); else printf("Invalid Color: %s\n\n", target); printf("Do you want to decode another resistor?\n => "); scanf("%c%c", &char_left, &reply); printf("\n"); } } while(►); /* function takes as input a list of strings, its size, and a target string. Then, searches the list for the target and returns as its value the subscript of the target in the list. It returns -1 if target is not found. */ int search(const char COLOR_CODES[][SUB_2], const char target[], int size){ int i, j; /* counters */ int length, counter=0; int found = 0; /* indicates when string is found*/ int where = 0; /* location of target*/ length = strlen(►); for(i=0; ►; i++) { for(j = 0; j < length; j++) if(►== target[j]) counter++; if(counter == length) found = 1; else counter=0; } --i; if(found) where = ►; else where = ►; return where; }
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
c language
Fill in the parts indicated by ► (meaning missing items).
/*
This program prompts for the colors of three bands of a resistor, and displays the * value of the
resistance in kilo-ohms based on a color code
*/
#include <stdio.h>
#include <math.h> /* for pow*/
#include <ctype.h> /* for toupper*/
#include <string.h> /* for strlen*/
#define NOT_FOUND -1 /* constants */
#define SUB_1 10
#define SUB_2 7
int search(const char [][SUB_2], const char [], int);
int main(void){
char reply, /* user reply*/
char_left; /* character left in the input stream*/
int i;
int counter; /* counters */
int value; /* subscript of target found in list*/
double answer = 0.0; /* value of resistor in kilo-ohms*/
int no_error = 1; /* denotes no error */
/* initializing the array*/
char COLOR_CODES[SUB_1][SUB_2] = {"black", "brown", "red", "orange","yellow", "green",
"blue", "violet", "gray", "white"}; char target[SUB_2]; /* target string array*/
do{
printf("Enter the colors of the resistor's three bands, beginning with\n");
printf("the band nearest the end. Type the colors in lowercase letters only, ");
printf("NO CAPS.\n\n");
for(counter = 1; ►; counter++) {
printf("Band %d => ", counter);
scanf("%s", target);
value = search(►, ►, SUB_1);
/* searches for string*/
if(value != NOT_FOUND) {
switch(counter){
case 1:
answer = value * ►;
break;
case 2:
answer += value;
break;
case 3
if (value>3)
answer+=pow(►);
else
for(i = 0; ►; i++)
answer /= 10;
}
}
else
no error = 0; /* if string not found*/
}
if (►)
printf("Resistance value: %.3f kilo-ohms\n\n", answer);
else
printf("Invalid Color: %s\n\n", target);
printf("Do you want to decode another resistor?\n => ");
scanf("%c%c", &char_left, &reply);
printf("\n");
} } while(►);
/* function takes as input a list of strings, its size, and a target string. Then, searches the list for the
target and returns as its value the subscript of the target in the list. It returns -1 if target is not found.
*/
int search(const char COLOR_CODES[][SUB_2], const char target[], int size){
int i, j; /* counters */
int length, counter=0;
int found = 0; /* indicates when string is found*/
int where = 0; /* location of target*/
length = strlen(►);
for(i=0; ►; i++) {
for(j = 0; j < length; j++)
if(►== target[j])
counter++;
if(counter == length)
found = 1;
else
counter=0;
}
--i;
if(found)
where = ►;
else
where = ►;
return where;
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images