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
pentagon [3]
2 years ago
6

New and just need help with C coding. I've tried if statements and it outputs the wrong number.

Computers and Technology
2 answers:
dimaraw [331]2 years ago
7 0

Answer:

#include <stdio.h>

int main(void) {

 

 int num1;

 int num2;

 int num3;

 printf("Enter three integers: ");

 scanf("%d", &num1);

 scanf("%d", &num2);

 scanf("%d", &num3);

 if (num1 == 0 || num2 == 0 || num3 == 0)

 {

   printf("please input a number greater than zero :)\n");

 }

 if (num1 <= num2 && num1 <= num3)

 {

   printf("%i is the smallest number!\n", num1);

 }

 else if (num2 <= num1 && num2 <= num3)

 {

   printf("%i is the smallest number!\n", num2);

 }

 else

 {

   printf("%i is the smallest number!\n", num3);

 }

 return 0;

}

Explanation:

Alright so let's start with the requirements of the question:

  1. must take 3 integers from user input
  2. determine which of these 3 numbers are the smallest
  3. spit out the number to out

So we needed to create 3 variables to hold each integer that was going to be passed into our script.

By using scanf("%i", &variableName) we were able to take in user input and  store it inside of num1, num2, and num3.

Since you mentioned you were new to the C programming language, I threw in the first if statement as an example of how they can be used, use it as a guide for future reference, sometimes it's better to understand your code visually.

Basically what this if statement does is, it checks to see if any of the integers that came in from user input was the number zero, it told the user it does not accept that number, please input a number greater than zero.

if (num1 == 0 || num2 == 0 || num3 == 0)

 {

   printf("please input a number greater than zero :)\n");

 }

I used this methodology and implemented the heart of the question,

whichever number is smaller, print it out on the shell (output).

if (num1 <= num2 && num1 <= num3)

^^ here we're checking if the first variable we created is smaller than the second variable and the third ^^

 {

   printf("%i is the smallest number!\n", num1);

   ^^ if it is smaller, then print integer and then print a new line so the next line looks neat ^^

   ( incase if your wondering what "\n" is, its a special character that allows you so print a new line on the terminal, kind of like hitting the return or enter key )

 }

else if (num2 <= num1 && num2 <= num3)

^^ else if is used when your checking for more than one thing, and so for the second variable we checked to see if it was smaller than the first and third variable we created ^^

 {

   printf("%i is the smallest number!\n", num2); < -- and we print if it's smaller

 }

Last but not least:

else

^^ if it isn't num1 or num2, then it must be num3 ^^

 {

   printf("%i is the smallest number!\n", num3);

  we checked the first two options, if its neither of those then we have only one variable left, and thats num3.

 }

I hope that helps !!

Good luck on your coding journey :) ‍

Zepler [3.9K]2 years ago
5 0

The Answer is in Bold: c++ language  

#include <iostream>

using namespace std;

int main() {

    int  a, b, c;      

cin >> a;        

cin >> b;

cin >> c;

  if (a < b && a < c)   {            

   cout << a <<endl;              

 }                                                    

else if(b < a && b < c)   {      

    cout << b << endl;

 }

 else   {

    cout << c <<endl;

}    

 return 0;

}

You might be interested in
Which major and minor keys have no sharps or flats apex?
9966 [12]
C major and A minor have no sharps or flats.
5 0
2 years ago
Read 2 more answers
Why do we need multitasking functionality in an Operating System?
Leokris [45]

Answer:

Multitasking is a process in which we do multiple task at a time.    

In computing system, multitasking is the concept of performing different types of multiple task and process over a certain period of time by executing simultaneously.

Operating system basically allow various task to run simultaneously by the user. In an operating system, each task consume storage system and all the other resources.

Multitasking function facilitate memory isolation in the processor and also supported different levels of security system in the operating system. For example, "a programmer working on any program in a system and as well as listening the music then, it perform multiple task at the same time".

7 0
2 years ago
What is the purpose of creating a primary key in a database
ss7ja [257]

Answer:

Basically it creates a unique identifier for each row in your table and that can help you link your table to other tables using primary key as link

Explanation:

"Primary key allows you to create a unique identifier for each row in your table. It is important because it helps you link your table to other tables (relationships) using primary key as links."

7 0
3 years ago
Research the design basis threat (DBT) in terms of Cybersecurity for an organization of your choice. Discuss what the Cybersecur
tiny-mole [99]

A Design Basis Threat (DBT) is known to be a characteristics of any given or potential insider and also those of external adversaries, that may try to have or gain unauthorized removal or sabotage, against a physical protection system that was set up designed and evaluated.

<h3>What are Cybersecurity objectives?</h3>

Cybersecurity aims are:

  • To protect computer system,
  • To protect networks,
  • To protect software programs from such cyber attacks.

Note that a lot of digital attacks are targeted at accessing, changing, or deleting sensitive information as well as others.

Learn more about IT from

brainly.com/question/1276995

#SPJ1

3 0
1 year ago
Care should be taken whenever you post comments or photos to any social media or other websites, because each of these online ac
REY [17]

Answer:

True

Explanation:

Building your personal brand requires extreme care when it comes to social media presence. In the age of internet there is nothing hidden, so whatever you post or comment will be seen by your audience and it can go in either way. It can either make your brand or break it. It is of utmost importance to leave a pleasant and positive impact on your audience. One should not indulge in inappropriate or controversial debates and try to avoid being too personal on social media.  

6 0
3 years ago
Other questions:
  • What does "FDDI" stand for in Technology?
    5·2 answers
  • Which statement is true about the elements of the interface of a presentation program? The status bar appears at the top of the
    14·2 answers
  • HELP ME PLZ QUICK Adam is writing a program that: 1) has the user guess a number, and 2) tells the user how many guesses it took
    6·1 answer
  • ___ involves connecting geographically remote computers into a single network and combining the computational power of all compu
    14·1 answer
  • You are utilizing BitLocker Drive Encryption, and are attempting to update Windows Server 2016. What must be done so that the up
    14·1 answer
  • Use the Date object and the Array object to determine and diplay information about the current date on your webpage. Your output
    11·1 answer
  • What form of contacts can be shared in Outlook 2016?
    9·2 answers
  • ____ the most popular word processing applications software<br><br>​
    12·1 answer
  • Cybersquatters:_________.
    5·1 answer
  • Josh is learning about hackers known for causing damage and altering functions of websites. Which type of hacker is he learning
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!