Need help analyzing this C program?

I don’t understand why while(status == ) works in this program, and why it doesn’t work if I have while(status == )? Thank You,

#include <stdio.h>

int main(void)

{

int num;

int sum = ;

int status;

printf(“Please enter an integer to be summed”);

printf(“(q to quit):”);

status = scanf(“%d”, &num);

while(status == )

{

sum = sum + num;

printf(“Please enter next integer(q to quit):”);

status = scanf(“%d”, &num);

}

printf(“Those integers sum to %d.n”, sum);

return ;

}

✅ Answers

? Favorite Answer

  • scanf() returns the number of items that it could convert. Since you have “%d” that is a single conversion. So, scanf() will return or . If you had “%d %d”, that would be two conversions, and scanf would return , or (depending on what it could convert).

    I don’t know where you got from – q is not a number, so scanf() can’t convert, and returns .

    Also, scanf() can return EOF (- typically) if end of input is reached before the first successful conversion (or matching failure). EOF is also returned on a read error. If a negative return from scanf() is seen, you can look at the errno variable for more details on the error (interrupted, out of memory, range, etc.).

  • Ah, I think you misunderstand how scanf works. Scanf will take the number given and store it into the address you give it (in your case, the num variable). It then returns if it succeeded or (I’m guessing) if it fails.

    Having while status== will never occur, since scanf won’t return .

  • The on an analogous time as loop above converts a binary huge type (base ) represented as a string of s and s right into a decimal (base ) fee. As for something? it is not being “declared” , the logo % is the C operator for modulo. In computing, the modulo (frequently pronounced as modulus) operation unearths something of branch of one huge type by skill of yet another. Given helpful numbers, a (the dividend) and n (the divisor), a modulo n (abbreviated as a mod n) is something of the Euclidean branch of a by skill of n. working example, the expression ” mod ” could evaluate to a million because of the fact divided by skill of two leaves a quotient of two and a the remainder of a million. In environments without modulus operator the equivalent calculation could be; a – (n * int(a/n)) So on your code above; the line “the rest=binaryNumberp.c.;” could be examine; the rest is-equivalent-to the fee of the identifier “binaryNumber” mod

    See also  If my school computers have full adobe apps can i get them on my home computer?
  • that is because scanf() returns the number of successful conversions.

    http://wpollock.com/CPlus/PrintfRef.htm#scanfRetCo…

    so in your case scanf will return or or EOF

    it will never return since you are asking only for one item to be entered.

    Source(s): http://wpollock.com/CPlus/PrintfRef.htm#scanfRetCo…

  • Other Related Questions

    Learning Visual Basic ?

    Answers Favorite AnswerTry using "System.Diagnostics.Process. GetProcessesByName( "iwmp" ).Length > " for your check.

    Microsoft Office word Fast answer needed its urgent?

    Answers Favorite AnswerTry this:http://www.techsupport.com///microsoft-wo...Here is another thread re: the same issue with instructions:http://www.pcreview.co.uk/forums/modification-not-...http://www.techsupport.com///microsoft-wo...http://support.microsoft.com/kb/http://answers.microsoft.com/en-us/office/forum/of...

    Can I download a whole city android google maps?

    Answers Favorite Answer:) Yes!!!Interesting question. I wonder why it has blocked in this way especially considering that Google Earth is very detailed and has good maps of Israel.

    What is meant by ROM ? Explain in simple but elaborate terms.What about mobile ROM’s?

    Answers Favorite AnswerHi Diva below is a link that will give a simple answer.http://wiki.answers.com/Q/What_does_ROM_stand_for_...Hope this helps.Source(s): Experience and wiki answers.ROM is Read only memory. i.e data can write only once.There two types of ROM..ROM.PROMThe difference between ROM and PROM.that is ROM is programmed during manufacturing it means data stored by manufacturing company.PROM is blank memory that a user programmable memory.user can store content on PROM.both ROM and PROM are Read only memory Data can write only once.and its not possible to write so many time.Memories of PROM and ROM are Non-volatile in nature. Its that stored informations can retain even power goes off.

    Leave a Comment