1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Murljashka [212]
3 years ago
7

2.8 Code Practice: Question 1

Computers and Technology
2 answers:
likoan [24]3 years ago
6 0

Input: A = 2, B = 8, C = 1

Output: Largest number = 8

-BARSIC- [3]3 years ago
4 0

Answer:

The program to this question can be given as:

Program:

#include <stdio.h> //define header file

int main() //define main method.

{

int a1,b1,c1; //define variable

printf("Enter three numbers:\n"); //message

scanf("%d",&a1); //input numbers.

scanf("%d",&b1);//input numbers.

scanf("%d",&c1);//input numbers.

if (a1>b1) //check condition

{

//check condition

if(a1>c1)//inner if block

{

printf("The largest number: %d", a1); //message

}

else  //inner else block

{

printf("The largest number: %d", c1);//message

}

}

else //else block

{

//check condition

if(b1>c1) //inner if block.

{

printf("The largest number: %d", b1);//message

}

else //else block

{

printf("The largest number: %d",c1);//message

}

}

return 0;  //return 0.

}

Output:

Enter three numbers:

22

44

11

The largest number: 44

Explanation:

The description of the above program can be given as:

  • In the C language program firstly we define the header file. Then we define the main function. In the main function, we define three variables that are "a1, b1 and c1". In this variable, we take input from the user.
  • Then we define the conditional statements. In the if block we check if the value of a1 is greater then the value of b1 if this condition is true so we use another condition that if the value of a1 is greater then the value of c1. so, it will print the largest value. If the above condition is not true then it will go to else section.
  • In the else part we check the condition that if the value of b1 is greater then the value of c1. if it is true it will print the largest number value.  
You might be interested in
You are a desktop administrator for Nutex Corporation. A user reports that he is unable to access network resources. You notice
Tju [1.3M]

Answer:

The right answer is wire crimper tool.

Explanation:

According to the scenario, the most appropriate answer is the wire crimping tool because the wire crimping tool is a tool that can strip the wire then cut it in proper shape and then crimp the wire in the RJ45 connector very effectively.

RJ45 connector is a connector which is used in ethernet cables to connect to computers i.e. cat 5, cat 5e, cat 6, etc. these cable has 4 pairs of different color codes.

A wire crimper effectively connects the end of the cable to an RJ45 connector.

4 0
2 years ago
Is the type of vision useful in sending motion and objects outside normal vision
nlexa [21]
Yes it is in fact it is usful
8 0
2 years ago
E whether True or False.
Natasha_Volkova [10]

Answer:

Learn vocabulary, terms, and more with flashcards, games, and other study ... covers a large geographical area and is made up of many smaller networks. ... you share the cable infrastructure with your neighbors ... do you need if you want to connect two network segments together such as a ... the twists reduce crosstalk.Explanation:

5 0
2 years ago
Given a string variable string 's;', implement a tokenizer to identify the unique tokens contained in this string, identify all
Flauer [41]

Answer:

#include <iostream>

#include <string>

#include <vector>

#include <cctype>

#include <algorithm>

using namespace std;

void matrixInit( vector< vector<int> >& matrix, int numRows, int numCols);

struct TokenFreq{

string token;

int freq;

};

string spaces(string& istr, string& newstr);

void printVector(vector<TokenFreq> & tfVec);

void getTokenFreqVec( string& istr, vector<TokenFreq> & tfVecVec);

void selectionSort( vector<TokenFreq> & tokFreqVector );  

void insertionSort( vector<TokenFreq> & tokFreqVector );

//main

int main(int argc, const char * argv[]) {

 

vector<vector<int> > matrix;

matrixInit(matrix, 3, 4);

 

string ostr1 = " I do keep the main points straight in my head most of the time, and I do know where to find the details when I need them. by Bjarne Stroustrup";

string ostr2 = " ";

string ostr3 = "Your time is limited, so don’t waste it living someone else’s life.Stay Hungry. Stay Foolish.";

//string ostr = ostr2;

string istr;

 

cout << "Enter the text: ";

getline(cin, istr);

vector<TokenFreq> tfVec;

getTokenFreqVec(istr, tfVec);

selectionSort(tfVec);

insertionSort(tfVec);

return 0;

}

//-----

void selectionSort( vector<TokenFreq> & tokFreqVector ){

TokenFreq temp;

int min;

 

for( int i = 0; i < int(tokFreqVector.size()-1); i++){

min = i;

for (int j = i+1; j <int(tokFreqVector.size()); j++){

if (tokFreqVector[j].freq < tokFreqVector[min].freq)

min = j;

}

if(min!=i)

{

temp = tokFreqVector[i];

tokFreqVector[i] = tokFreqVector[min];

tokFreqVector[min] = temp;

}

}

cout<<"-----selectionSort------------------"<<endl;

printVector(tokFreqVector);

}

void insertionSort( vector<TokenFreq> & tokFreqVector ){

TokenFreq temp;

int max;

 

for( int i = 0; i < int(tokFreqVector.size()-1); i++){

max = i;

for (int j = i+1; j < int(tokFreqVector.size()); j++){

if (tokFreqVector[j].freq > tokFreqVector[max].freq)

max = j;

}

if(max!=i)

{

temp = tokFreqVector[i];

tokFreqVector[i] = tokFreqVector[max];

tokFreqVector[max] = temp;

}

}

cout<<"-----insertionsort------------------"<<endl;

printVector(tokFreqVector);

}

string spaces(string& istr, string & newstr){

int j;

//Check double space and create new string with lowercase

for (int i = 0; i < int(istr.length()); ++i){

istr[i] = tolower(istr[i]);

if (isspace(istr[i])){

//check double space again

j = i+1;

while(true){

if (istr[j] == '\342') istr[j]=' ';

if (istr[j] == '\200') istr[j]=' ';

if (istr[j] == '\224') istr[j]=' ';

if(isspace(istr[j])) j++;

else break;

}

i=j-1;

newstr = newstr + istr[i];

}else

newstr = newstr + istr[i];

}

return newstr;

}

void getTokenFreqVec( string& istr, vector<TokenFreq> & tfVec){

string newstr;

int curr_beg = 0;

int curr_end = 0;

string word;

bool check = false;

int index=0;

 

//call func spaces to get new string

newstr = spaces(istr, newstr);

//cout << newstr << endl;

//cout << endl;

//cout << newstr << "||" << endl;

string tempstr = newstr;

 

if(newstr != " "){

tfVec.push_back(TokenFreq());

}

for (int i = 0; i < int(newstr.length()); ++i){

if(isspace(newstr[i])){

check = false;

 

curr_end = i;

word = tempstr.substr(curr_beg, curr_end - curr_beg);

curr_beg = i + 1;

 

for (int j = 0; j < int(tfVec.size()); j++){

if (tfVec[j].token == word){

tfVec[j].freq++;

check = true;

 

break;

}

}//end-for;

if (check == false && i!=(int(newstr.length())-1)){

//cout <<"**"<< word <<"**"<<word.length()<< endl;

tfVec[index].token=word;

tfVec[index].freq=1;

index++;

tfVec.push_back(TokenFreq());

}

word = "";

//add last value

}

}//end-for

 

if(!isspace(newstr[int(newstr.length())-1])){

word = tempstr.substr(curr_beg, curr_end - (int(newstr.length())-1));

tfVec[index].token=word;

tfVec[index].freq=1;

//tfVec.push_back(TokenFreq());

}

 

printVector(tfVec);

}

void printVector(vector<TokenFreq> & tfVec){

 

cout << "size= {" << tfVec.size() << endl;

for (int i = 0; i < int(tfVec.size()); i++){

cout << " [" << i << "] = (token = \""<< tfVec[i].token <<"\", freq = " << tfVec[i].freq << ")" << endl;

//cout << tfVec[i].token<<endl;;

}

cout << endl;

}

void matrixInit( vector< vector<int> >& matrix, int numRows, int numCols){

int i;

int j;

matrix.resize(numRows, vector<int>(numCols) );

for(i = 0; i< numRows; i++ ){

for(j = 0; j < numCols; j++ )

matrix[i][j] = i*j;

}

 

cout << "size of matrix is: " << numRows << "x" << numCols << endl;

for (i = 0; i < numRows; i++){

for (j = 0; j < numCols; j++){

cout<< "matrix[" << i << "][" << i << "]=" << matrix[i][j] << endl;

}

}

cout << endl;

}

Explanation:

3 0
2 years ago
When do you use a for loop?
AleksandrR [38]

Answer:

You use a for loop when you know how many times you want to run the loop

Explanation:

if you dont know, use a while loop

6 0
2 years ago
Read 2 more answers
Other questions:
  • The steps for moving data from one cell to another are _____.
    14·1 answer
  • Technician A says you should measure the parasitic load immediately after the vehicle is turned off. Technician B says you shoul
    10·1 answer
  • Knowing what you know about today’s video games, imagine what it would look like if you had to create a modern-day version of Sp
    6·1 answer
  • What is the purpose of using a good e-mail technique?. Demonstrate your ability to write good e-mails b. Completely describe you
    8·1 answer
  • What are computer crimes?​
    14·1 answer
  • -1
    13·1 answer
  • The objective of this task is to use Scapy to estimate the distance, in terms of number of routers, between your VM and a select
    10·1 answer
  • In case of a suspected data breach, what course of action should a chief information security officer (CISO) take
    9·1 answer
  • Cual es el procedimientos para asistir en el transporte publico a personas discapacitadas
    6·1 answer
  • Cyber security class i need help​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!