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
Write a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters.
vichka [17]

Answer:

Explanation:

The python code for the question is attached in the image below.

The objective here is to write a code in python with a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters. Otherwise, it should return False.

SEE BELOW FOR THE CODE.

alphabet = "abcdefghijklmnopqrstuvwxyz"

test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]

test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"]

def histogram(s):

   d = dict()

   for c in s:

       if c not in d:

           d[c]=1

       else:

           d[c] += 1

   return d

def has_duplicates():

   for string in test_dups:

       dictionary=histogram(string)

       duplicates=False

       for ch in dictionary.keys():

           if dictionary[ch] > 1:

               duplicates=True

               break

       if duplicates==True:

           print(string,"has duplicates")

       else:

           print(string,"has no duplicates")

def missing_letters(string):

   answer=""

   for ch in alphabet:

       if ch not in string:

           answer=answer+ch

   return answer

print("__________________________________________")

print(" Calling has_duplicates() function")

print("__________________________________________")

has_duplicates()

print("\n______________________________________________")

print("Calling missing_letters() function in for loop")

print("______________________________________________")

for i in test_miss:

   answer=missing_letters(i)

   if len(answer)>=1:

       print(i,"is missing letters",answer)

   else:

       print(i,"uses all the letters")

3 0
3 years ago
How to use github to creat a blog?Thank you
stepan [7]
You can use GitHub Pages! They have tutorials on their site to help you set up using that (too much for this format!). You can use it to make your own personal site, as well as host any existing site you may have.
5 0
4 years ago
<img src="https://tex.z-dn.net/?f=%7B%5Chuge%7B%5Cunderline%7B%5Cbf%7B%5Cpink%7BQuestion%7D%7D%7D%7D%7D" id="TexFormula1" title=
Tom [10]

Based on the information given, the correct option will be [1,2 ] is the matrix to count all paths from top left to bottom right of M×N matrix.

  • A matrix simply means a set of numbers that are laid out on rows and columns. The numbers in matrix can represent either data or mathematical equations

  • It should also be noted that matrix can be used as way of providing quick approximation of calculations.

In conclusion, the correct option is [1,2 ] is the matrix to count all paths from top left to bottom right of M×N matrix.

Learn more about matrix on:

brainly.com/question/1821869

3 0
2 years ago
Read 2 more answers
State and explain ten features of the standard toolbar as in computing.
Anastasy [175]

Answer:

Hi. I'm glad to help you.

Explanation:

1. New blank document: It helps the user to create a new blank document or sheet.

2. Open: It allows the user to open or find a file.

3. Search: It is used to find files, folders and webpages.

4. Cut: It removes the current selection to the clipboard.

5. Copy: It copies the selection to the clipboard.

6. Print preview: It shows how a file will look like when printed.

7. Insert hyperlink: This command allows the user to insert a new hyperlink or edit the selected hyperlink.

8. Zoom: Adjusts the size that the document appears on the screen.

9. Document Map: It displays the document map for the current document.

10. Format Painter: It copies the cell format allowing it be pasted elsewhere.

<em><u>Hope it helps. Please mark as brainliest. </u></em>

4 0
3 years ago
Read 2 more answers
A feature of the IEEE 802.11n/ac standards for wireless networking whereby two or more antennas are used at both ends of transmi
Vitek1552 [10]

Answer:

Yes it is.

Explanation:

The IEEE 802.11n/ac standards for wireless networking use two antennas to improve the data rates, with these both antennas the transmission is better and the performance, MIMO is a technology that uses multiple antennas to coherently resolve more information than possible using a single antenna, this is the main feature for this technology.

5 0
3 years ago
Other questions:
  • Which of these is not a sub-claim "Our Clean Power Plan" uses to support its main claim? The CPP protects public health. The CPP
    13·2 answers
  • Which of the following would indicate that a website is a secure site?
    7·2 answers
  • A video games sell for $59.99..
    13·1 answer
  • Select the correct answer from each drop-down menu.
    8·1 answer
  • Consider a three sequentially stepped process named as Process A, Process B and Process C. Input comes into Process A. Output fo
    13·1 answer
  • True/False: The American Standard Code for Information (ASCII) is a code that allows people to read information on a computer.
    9·2 answers
  • 4.15 LAB: Password modifier
    14·1 answer
  • Directions: Identify the measuring devices and write its functions.
    9·1 answer
  • Martin is responsible for translating the script into a visual form by creating a storyboard. Which role is he playing?
    8·1 answer
  • Which statement is true of a science fiction story? WILL PAY GIVE CASH APP
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!