Write a program to enter the numbers till the user wants and at the end it should display the count of positive, negative and zeros entered
Let Us C Page 129 [B](g)
Let Us C Page 129 [B](g)
/*a program to enter the numbers till the user wants andThe Output - This program asks the user to enter a number and then gives the user a choice to enter another number. As long as the user selects 'Y', he can continue entering numbers. When he types anything other than 'Y', the while() loop breaks and a final count of numbers entered appears on the screen.
at the end it should display the count of positive, negative and
zeros entered
Author : Viks Von Doom
Date : 16/7/2016 Time 05.46 PM IST */
#include<stdio.h>
int main()
{
int num_1;
int count_zero = 0;
int count_positive = 0;
int count_negetive = 0;
char choice ='Y';
while(choice == 'Y')
{
printf("Enter a number : ");
scanf("%d", &num_1);
if(num_1>0)
count_positive = count_positive + 1;
else if (num_1 == 0)
count_zero = count_zero + 1;
else count_negetive = count_negetive + 1;
printf("Do you want to enter another number (Y / N) : ");
scanf("%s", &choice);
}
printf(" Number of positive integers : %d | Number of zeros : %d | Number of negetive integers : %d", count_positive, count_zero,count_negetive);
return 0;
}
No comments:
Post a Comment