loops - C program that displays the max of entered %2==0 numbers until you enter a number %2!=0 && %7==0 -
loops - C program that displays the max of entered %2==0 numbers until you enter a number %2!=0 && %7==0 -
this programme must take input user (a number) , repeat until odd number dividable 7 entered. must print maximum of numbers entered.
tried 2 ways : nested , double while loop. problem i'm having after come in number dividable 7 not odd (say 28) , if come in odd number (say 3) programme prints max. it's supposed allow me come in numbers 1 time again until come in 1 odd , dividable 7 (let's 21).
nested code:
#include <stdio.h> #include <stdlib.h> int main() { int x, max = 0, suma = 0, impar, par = 0; while (x % 7 != 0) { while(x % 2 == 0 || x % 2 != 0) { printf("introduceti united nations numar:\n"); //enter number scanf("%d", &x); if (x % 2 == 0) if (x > max) max = x; } printf("introduceti united nations numar:\n"); //enter number scanf("%d", &x); if (x % 2== 0) if (x > max) max = x; if (x % 2 != 0) break; } printf("maximul numerelor pare introduse este: %d",max); }
why we're @ , i'm having problem finding info nested while loops in c. inner loop tested first compiler? can explain simple example?
your code has undefined behavior, since have while
depends on x
before assign x
value. if you're going input value user, can't test value before reading it. while
loops not correctly expressing want do.
it can done using infinite loop, , break
ing out when necessary.
and no, loops (of course) not evaluated within out. evaluated in programme order.
c loops numbers nested
Comments
Post a Comment