Why do I keep getting 0 My C Code won't enter Switch

is return 0 necessary in c
return 0 in c with example
return 1 in c means
return 0 in java
return 0 or 1 in c
return in c
why do we write void main in c
return 0 and return

Write a C program that computes the maximum, minimum, sum and average of 4 integers.

This program reads 4 integers in decimal, hexadecimal or octal formats and a character that specifies the math operation (x for maximum, m for minimum, s for sum, a for average) from command prompt (xterminal on Ubuntu) and prints the result of the operation.

The input/output fomat details are provided below.

Result should be printed as integer for x, m and s operations; but as a floating point number for the average (a) operation.

The integer outputs will be printed in hexadecimal format, and the floating point values will be printed in scientific format. Input:

<number 1>[space] <number 2>[space] <number 3>[space] <number 4>[space] <operation>

Sample Input1: 0xFF 99 077 0 s , Expected Output1:0x1a1

Sample Input2:0x10 10 10 010 a , Expected Output2:1.100000e+01

Sample Input3: 0770 0xFF 270 0xAB m , Expected Output3: 0xab

Sample Input4: 010 0x10 10 0x3 x , Expected Output4:0x10

Here's the code I've written

#include <stdio.h>

int main() {
  int num1, num2, num3, num4;
  char op;

  scanf("%d%d%d%d%c", &num1, &num2, &num3, &num4, &op);

  switch (op)
    if (num1 > num2&&num1 > num3&&num1 > num4)
      printf("%d", num1);
    else if (num2 > num1&&num2 > num3&&num2 > num4)
      printf("%d", num2);
    else if (num3 > num1&&num3 > num1&&num3 > num4)
      printf("%d", num3);
      printf("%d", num4);
    if (num1 < num2&&num1 < num3&&num1 < num4)
      printf("%d", num1);
    else if (num2 < num1&&num2 < num3&&num2 < num4)
      printf("%d", num2);
    else if (num3 < num1&&num3 < num1&&num3 < num4)
      printf("%d", num3);
      printf("%d", num4);
    printf("%d", num1 + num2 + num3 + num4);
    printf(" %f", (num1 + num2 + num3 + num4) / 4);

  return 0;

You need to add space between %d's.Here is a good description why you need space . So the code will become

scanf("%d %d %d %d %c",&num1,&num2,&num3,&num4,&op);

To print in hexadecimal format you need to use, "%x" for ex.


To print in scientific format,use "%.10e"


One more thing,in order to get a floating point number in division and every number is integer, you need to make at least numerator or denominator floating point. In your case,


Multiple problems here: First problem: You're using both m and n before assigning them any valid value (so their initial value is most likely huge). Second​  I am wondering why my C program does not print any information. I am 100% new to programming, and have been able to learn a few things in Ruby and Python these past few weeks, but I am getting nowhere with the C stuff. Here is the total baseline, simple program that everyone learns first:

Adding a printf("0x%2x", op); after your scanf() results in 0x20 being printed out.

0x20 is the hex value for the space character, thus confirming our suspicions that a whitespace character was being read instead of your wanted operator.

Replacing the format string in scanf() (%d%d%d%d%c) with %d%d%d%d %c causes the method to work properly, since the whitespace character is now ignored before the operator.

Input: 1 2 3 4 x

Output: 4

In a C++ program the statement is optional: the compiler automatically adds a return 0; if you don't explicitely return a value. The return value is the exit code of your program, the shell (or any other application that ran it) can read and use it. Pro Users: Click on Defer Upgrades-that would change your Windows update server and the problem would be resolved.However,upgrades would be postponed.Another Alternate Download version 1511 through media creation Tool and perform an In-place upgrade.This would make sure you are on the latest build of windows 10 and you would receive the

If you use void main(), then you do not have to call return. What is the output of below code in C: y = 4 || -1 && 0? However, main returns are useful for debugging, program analysis and lots of stuff when you get serious with While coding in C-we use int main() and return 0 [in the end]- and we run it, why doesn't the  If you decide to ignore the errors, you can disable script debugging. To do this, select the Disable script debugging (Internet Explorer) checkbox in the Internet Options -> Advanced -> Browsing settings. Note If this problem occurs on more than one or two sites, do not disable script debugging.

C 803 44-4-0 80 *- C 7 DROPS, TOP 7 CC/B01 TLF 44, 4–C 805 4, 44–0 cc / any TLE My-cort 4 **-C 6 38 444-C 6 38-31 Lori ON, TOP 1 0 1/801 I Lo 444-0 ool 4 FoR RFCONST 1 Turton, 100,000 UNI is scC 24 do SF / Bot I LE DROPPER  Trying to sum column but getting 0 as result I've copied information into an excel spreadsheet, and I'm trying to sum certain columns, however my formula is returning the result of "0". The column I'm trying to total has numbers such as 2.0, 16.0, etc. so I'm thinking it has something to do with the formatting in these cells, however I can't

std::cout << x; // who knows what we'll get, because x is uninitialized If your compiler won't let you compile and run the above program for this reason, to get assigned to a spot of memory that had a reasonable value in it, like 0). says​, “You said I couldn't do X, but I did it anyway and my program works! A Blue Screen of Death (BSOD), also called a STOP Error, will appear when an issue is so serious that Windows must stop completely. A Blue Screen of Death is usually hardware or driver related. Most BSODs show a STOP code that can be used to help figure out the root cause of the Blue Screen of Death.

So here is my attempt to catalog some of the common and not so common mistakes In VC++, the result will be 0 but that is not guaranteed by the C standard. When you run this code, you get the following output with the first line determine the size of the char array but a pointer to the array won't. Open an elevated command prompt. To do this, right click the Windows button, and then select Command Prompt (Admin). If you are prompted for an administrator password or for a confirmation, type the password, or click Allow or Yes. Type the following command, and then press Enter.

  • Before the switch, you should display what values have been read (with some printf("%d... %c", ...);
  • the problem may be with the %d%d%d%d%c format string. you are wanting the inputs to be spaced out, but the format string doesn't. (at least for the %c part)
  • The op read the space character between the 4th number and <operation> instead of <operation> character. Try once with eliminating the space between 4th number and <operation> or add space between %d and %c.
  • Also, always check the return value of scanf to see whether it parsed all the values you wanted. Otherwise you could be using uninitialized variables.
  • As a general rule -- an important one which I strongly recommend to follow -- one should inspect the return values of functions. scanf() returns the number of items successfully converted; in your case it should return 5, I think. Does it?
  • %d already skips leading whitespace; it's just the %c that needs a space before.
  • The %d operations already skip white space; the spaces between then are not needed. The space between %d %c is crucial; the %c (and %[…] and %n) conversion specifiers do no skip white space.