Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Saturday, July 16, 2016

A program to enter numbers and to display the count of positive, negetive and zeros entered

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)



/*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

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;
}
 The 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.

A program to calculate overtime pay of 10 employees. Overtime is paid at the rate of Rs. 12.00 per hour for every hour worked above 40 hours.

Write a program to calculate overtime pay of 10 employees. Overtime is paid at the rate of Rs. 12.00 per hour for every hour worked above 40 hours. Assume that employees do notwork for fractional part of an hour
Let Us C page Page 128 [B] (a)

/*Write a program to calculate overtime pay of 10 employees. Overtime is paid at the rate of Rs. 12.00 per hour for every hour worked above 40 hours. Assume that employees do not work for fractional part of an hour*/ 

#include<stdio.h>

/*Write a program to calculate overtime pay of 10 employees.
Overtime is paid at the rate of Rs. 12.00 per hour for every
hour worked above 40 hours. Assume that employees do not
work for fractional part of an hour


Author : Viks Von Doom 
Date 16/07/2016 Time 1:30 PM IST*/

int main()
{
    int ovr_rate = 12;
    int std_hr = 40;
    int hr_worked;
    int ovr_hr;
    int count = 1;
    int pay;

    while (count <= 10)
    {
        printf("\n Enter the Hours worked : ");
        scanf("%d", &hr_worked);
        ovr_hr = hr_worked - std_hr;
        if (ovr_hr > 0)
        {
            pay = ovr_hr*ovr_rate;
            printf("The Over Time Pay is: %d",pay);
        }
        else printf("Not eligible for overtime pay");

        count = count + 1;
    }


return 0;
}


The output is perfectly the way I wanted it to be. If the employee has worked for less than or equal to 40 hours, the program displays a message that he is not eligible for the overtime pay. for any hour of work over 40 hours, the program displays the payment eligible.