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
Nowadays, most online discussion boards are on Web-based forums that provide a variety of user-friendly tools to create and post
Katyanochek1 [597]

Answer:

The correct answer to the following question is option e.) Usenet.

Explanation:

Usenet - it  is a collection of the user-submitted messages or notes on the various subject that posted to the servers on the worldwide network. Each of the subject collection of notes is known as newsgroups. There are thousands of the newsgroups which is possible for us to form the new one.

It works like the decentralized computer network which allows us to download our required files. We can also download and access the binary files along with the text post.

5 0
3 years ago
Write a program that uses the function isPalindrome given in Example 6-6 (Palindrome). Test your program on the following string
WITCHER [35]

Answer:

Explanation:

bool isPalindrome(string str)

{

   int length = str.length();

   for (int i = 0; i < length / 2; i++) {

      if (str [i] != str [length – 1 – i]) {

         return false;

         }

    }

cout << str << "is a palindrome";

return true;

}

3 0
3 years ago
Using the Caesar cipher, "HELLO" is encrypted to "OLSSV" by applying a shift of 7. The number 7 is considered the __________
Semenov [28]

Answer:

The offset

Explanation:

In the question, we understand that the original text is HELLO and the encrypted text is OLSSV.

It should be noted that O replaced H, L replaced E, S replaced L and V replacement O.

This is made possible by a term refered to as offset.

The offset is used to determine the character that will replace another when it is encrypted.

7 characters after H is O; this is same for every other characters in the text.

8 0
2 years ago
Dwayne Alexander is working on a project promoting a fictitious product for his marketing class. He wants to use animation to sh
erastova [34]

The following are examples of animation apps:

  • Toon Boom Animation (2-D)
  • Prisma3D (3-D) and
  • AnimeTok (3-D)

<h3>What are the Pros and the cons of each app listed above?</h3>

Toon Boom Animation Pros:

  • It has a great set of tools
  • It has camera angles functionality
  • Has a vector drawing tool

Cons:

  • It is expensive.

Prisma3D (3-D) Pros:

  • It is good for modeling;
  • Easy to use interface

Cons:

  • It has too many bugs.
  • lacks sculpting tools

AnimeTok (3-D) Pros:

  • It makes it easy to move the characters easily
  • It is easy to understand

Cons:

  • It has too many ads
  • does not have an undo and redo button

Learn more about Animation Apps at:
brainly.com/question/7279789

6 0
2 years ago
A ___________ is similar to an intranet in that it uses internet technologies, but is developed for users outside the organizati
Vanyuwa [196]
The blank is extranet
I hope this helped!
6 0
3 years ago
Other questions:
  • You should use _____ software for writing a letter.
    10·1 answer
  • What are the pros and cons of editorial anonymity?
    13·1 answer
  • The CUSTOMERS and SALES tables contain these columns:
    6·1 answer
  • Differences between electromechanical era and electronic era in point.<br>PLZ HELP​
    6·1 answer
  • A Windows application which demands a lot of raw processing power to execute repetitive complex calculations is a good candidate
    9·1 answer
  • What do you call the spreadsheet cell that is in effect and has a heavier black border around it?
    7·2 answers
  • A or an is a simple chip with two or more processor core
    5·1 answer
  • How to make a website
    15·2 answers
  • QUESTION 4
    13·1 answer
  • Why is computer science hardware needed to solve problems with computers?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!