Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int sp = 0;
- int sn = 0;
- int x;
- int counterP=0;
- int counterN=0;
- do{
- printf("Podaj liczbe ");
- scanf("%i", &x);
- if(x!=0){
- if(x%2==0){
- sp = sp + x;
- counterP++;
- } else {
- sn = sn + x;
- counterN++;
- }
- }
- }while(x!=0);
- if(counterN>0){
- float sredniaN = (float)sn/counterN;
- printf("Srednia liczb nieparzystych to: %f \n", sredniaN);
- } else {
- printf("Brak liczb nieparzystych \n");
- }
- if(counterP>0){
- float sredniaP = (float)sp/counterP;
- printf("Srednia liczb parzystych to: %f \n", sredniaP);
- } else {
- printf("Brak liczb parzystych \n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment