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
Please answer quick :(​
Karo-lina-s [1.5K]

Answer:

1<2 or 15<6 is true

2<4 and 7< 3 is false

not(7>2) is false

6 0
1 year ago
Read 2 more answers
What is the Multiplier if the change in RGDP is $525,000,000 and initial spending is $100,000?
OLEGan [10]
The right answer is A
4 0
3 years ago
To have a set of command
GalinKa [24]

Every program that interacts with people responds to a specific set of commands. The set of commands and the syntax for entering them is called the user interface and varies from one program to another. The DOS operating system makes a distinction between internal and external commands.

3 0
2 years ago
What is meant by byte in computer terminology​
dsp73

Answer:

Byte, the basic unit of information in computer storage and processing. A byte consists of 8 adjacent binary digits (bits), each of which consists of a 0 or 1. The string of bits making up a byte is processed as a unit by a computer; bytes are the smallest operable units of storage in computer technology.

Explanation:

Can I be brainliest? TYSMMMMMM      

7 0
3 years ago
Read 2 more answers
All organizations with a router at the boundary between the organization’s internal networks and the external service provider w
Anika [276]

Answer:

False

Explanation:

Access Control Lists (ACLs) are network filters used by routers and some switches to permit and restrict data flows in and out of network devices. When an ACL is implemented in a device or interface, the network device analyses data passing through it, compares it to the specification described in the ACL, and allows it the data to flow or prohibits it. One of the main reasons ACLs arre used is to provide a basic level of security for networks. If anything, the use of ACLs and their complexities bring about a delay in transmission through networks.

3 0
2 years ago
Other questions:
  • What is one visual indication that a usb port can be used to charge a mobile device?
    13·1 answer
  • Computer communications describes a process in which two or more computers or devices transfer ____.
    10·1 answer
  • Some people are unable to arrange six matches to form four equilateral triangles because they fail to consider a three - dimensi
    6·1 answer
  • What will be the value of i after the C statements at the right have been executed
    6·1 answer
  • Judy forgot where she saved a certain file on her computer. Therefore, she searches for all files with a .jpg file extension. Wh
    10·2 answers
  • Which version of Windows was considered an operating environment rather than an operating system? Windows 1.0 Windows 3.0 Window
    9·1 answer
  • The characteristics of Computer Graphics<br><br>FUEL YOUR<br>GREATNESS​
    9·1 answer
  • Which of the following methodologies might be most appropriate if you have a system project with:unclear user requirements; unfa
    12·1 answer
  • Many digital libraries have much more information than traditional libraries
    13·1 answer
  • Which option ensures that items in a text box or table cell will be in the absolute center of that element?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!