Computer Science, asked by afrozaakther38, 7 days ago

Write a program to add numbers entered by the user as long as the user wants​

Answers

Answered by Roshniiii07
2

Answer:

#include<stdio.h>

#include<conio.h>

int main()

{

int number, positive = 0, negative = 0, zero = 0;

char choice='Y';

do

{

printf("Enter a number: ");

scanf("%d", &number);

if (number > 0)

{

positive++;

}

else if (number < 0)

{

negative++;

}

else

{

zero++;

}

printf("Do you want to Continue(y/n)? ");

scanf(" %c", &choice); //note the space before " %c" otherwise your while loop would not work

}while(choice == 'y' || choice == 'Y');

printf("\nPositive Numbers :%d\nNegative Numbers :%d\nZero Numbers :%d", positive, negative, zero);

}

Explanation:

Output:

Enter a number: -4

Do you want to Continue(y/n)? y

Enter a number: 0

Do you want to Continue(y/n)? y

Enter a number: 7

Do you want to Continue(y/n)? y

Enter a number: -45

Do you want to Continue(y/n)? y

Enter a number: 12

Do you want to Continue(y/n)? n

Positive Numbers :2

Negative Numbers :2

Zero Numbers :1

Similar questions