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]
3 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]3 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]3 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 grapgic element loads faster when used with text or audio
myrzilka [38]

Answer:

is there a multipule choice

Explanation:

7 0
3 years ago
4. An advantage presented by straight-in spaces is that
zmey [24]

Option B

Explanation

Straight-in parking is an approach of parking where vehicle is approached and parked safely in between the guiding lines. It thus helps to prevent blockage of cars. Each car can move in and out freely preventing it from congestion.

Straight-in parking is the most traditional approach of parking which saves time for drivers, allows for two-way traffic as well as driver can line up from multiple angles. Hence option B is the most appropriate one.

8 0
3 years ago
A relational database is different from a simple database because it has more than one _____.
arsen [322]

Answer:

A relational database is different from a simple database because it has more than one _____.

The answer to this should be more than one tables

Explanation:

The main difference between simple database and relational database is there data storing technique like simple database store data in the form of files and in relational database for data arrangement tables are used where the header is the name of of attributes/columns and rows contain the values of those attributes. Other difference is that simple database might be single user but relational database is multi user. There are many other difference are also available which make Relational Database the advance version.

I hope it will help you!

5 0
3 years ago
A occurs when you reset a mobile device but retain your installed applications and personal settings
yaroslaw [1]

Answer:

Soft Reset

Explanation:

A Soft Reset is a type of reset in which a gadget such as smartphones, PC, or other related gadgets undergo to refresh or reset the device or makes certain applications work or function well without user data, settings and applications.

Hence, a SOFT RESET occurs when you reset a mobile device but retain your installed applications and personal settings

3 0
3 years ago
Read 2 more answers
Which option allows users to access the handout master to modify it?
leonid [27]

Answer:

b

Explanation:

im the goat

3 0
3 years ago
Read 2 more answers
Other questions:
  • A file must be ________ before data can be written to or read from it. closed opened buffered initialized none of these
    11·2 answers
  • Given the strings s1 and s2 that are of the same length, create a new string consisting of the last character of s1 followed by
    10·1 answer
  • 1. You have recently been hired by a leading firm, which provides information management solutions to large corporations. As a n
    12·2 answers
  • What can happen if you do not follow the directions when cooking or baking? (Give 4 examples in a sentence each)
    8·1 answer
  • Data is best described as
    10·2 answers
  • Name any four areas where computers are used​
    15·1 answer
  • Please answer this question​
    8·1 answer
  • Which two features offered by SharePoint
    12·1 answer
  • Describe a NIC card and can you have more than one?
    13·1 answer
  • Which of the following statements are TRUE about formatting images in HTML.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!