Question
C linux
please write it by only using “if and else” conditions, thanks so much
Requirements 1. Copy your solution for Task 3 t3.c to a new file t4.c. 2. The input is guaranteed to contain at least one non
this is my task 3
1 2 3 #include <stdio.h> #include<math.h> int main() float i; scanf(%f,&i); int x =floor(i); int y =round(i); int z =ceil(i
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include<math.h>

int main()
{
   float i;
   int input = scanf("%f",&i);     // input will contain the return value of scanf() function if its zero then if condition gets true
   if(input == 0)
   {
       printf("scanf error: (%d)\n",input);
   }
   else
   {
   int x = floor(i);
   int y = round(i);
   int z = ceil(i);
  
   printf("%d ",x);
   printf("%d ",y);
   printf("%d\n",z);
   }
   return 0;
}

input : sausage

output :

scanf error: (0)

input : 3.14

output : 3 3 4

Add a comment
Know the answer?
Add Answer to:
C linux please write it by only using “if and else” conditions, thanks so much this...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • the coding language is just the basic c language and here is my first attempt at...

    the coding language is just the basic c language and here is my first attempt at this problem my problem is that if the user inputs a number that is equal to a number that has been entered previously the code will never end until the user enters a number that is bigger than any other number previously entered any help will be helpful Write a program to read-in a sequence of integers from the keyboard using scanf(). Your program...

  • Please, I need help, I cannot figure out how to scan variables in to the function...

    Please, I need help, I cannot figure out how to scan variables in to the function prototypes! ******This is what the program should look like as it runs but I cannot figure out how to successfully build the code to do such.****** My code: #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> #include <conio.h> float computeSeriesResistance(float R1, float R2, float R3); float computeParallelResistance(float R1, float R2, float R3); float computeVoltage(int current, float resistance); void getInputR(float R1, float R2, float R3); void getInputCandR(int...

  • I have a question on an assignment for C++. I have my code available here and...

    I have a question on an assignment for C++. I have my code available here and just want someone to look over it using MS VS 2010 express, for that is what my instructor is using. Write a program that mimics a calculator. The program should take as input two integers and the opreation to be performed. It should then output the numbers, the operator, and the result. (For division, if the denominator is zero, output an appropriate message.) //**This...

  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

  • C program. Using do-while loop for this question. Question: write a program to calculate the average...

    C program. Using do-while loop for this question. Question: write a program to calculate the average of first n numbers. output: Enter the value of n : 18 The sum of first 18 numbers =171 The average of first 18 numbers = 9.00 my code couldn't give me the right avg and sum. Please help. #include<stdio.h> int main() {     int num;     int count =0;     int sum=0;     float avg;      printf("Enter the value of n: ");    ...

  • 1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf...

    1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf ("Hello!") return 0 2 Assume a program has the following declarations: short s- 4 int i--5; long m-3 float f-19.3f; double d-3.6; What are the following values? (a) s+m (b) (float) d (c) d s (e) (int) f 3 What will be the output of the following program: int x = 3 float a 2.76; y-2* x; print f("X-2d, y*ta, z»%d", x, y, z);...

  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

  • answer two question,each question has 3syntax errors,find it. 1(a) The following segment of code contains at...

    answer two question,each question has 3syntax errors,find it. 1(a) The following segment of code contains at least three (3) syntax errors that will compilation to fail with errors. Identify each of these errors and specify the solution. [2 marks each, 6 marks in total] cause #include <stdio.h> void main (void) float height; float area; printf "input height of the rectangle: ") scanf( "%f", &height) printf"input length of the rectangle: scanf"", &length); height length; area printf( area of rectangle %f high...

  • Please I need help in C language, I am trying to modify the code per the...

    Please I need help in C language, I am trying to modify the code per the below instructions, but I am getting errors. Can't fgure it out. The attempted code modification and data file is privided below, after the instructions. Thank you. Instructions:                  1.      First, add a function named printMsg that displays a message, a greeting, or an introduction to the program for the user. Add a statement that calls that function from the main function when your program starts....

  • Write a C program that calculates exact change. In order to receive full credit, please remember...

    Write a C program that calculates exact change. In order to receive full credit, please remember that only int arithmetic is exact, so you’ll need to break up your double into two ints, the one before the decimal point and the one after the decimal point. Another point worth mentioning is that the % operator gives the remainder. In other words, when working with int values, 9 / 5 = 1 whereas 9 % 5 = 4. Keep this in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT