0% found this document useful (0 votes)
3 views

C Programs Week3

The document contains three C programs: the first checks if a given alphabet is a vowel or consonant, the second determines if a number is positive, negative, or zero using an else if ladder, and the third calculates an electricity bill based on unit consumption with specified rates for different ranges. Each program includes the necessary code and conditions for execution. The programs demonstrate basic conditional statements and user input handling in C.

Uploaded by

boddanaomkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

C Programs Week3

The document contains three C programs: the first checks if a given alphabet is a vowel or consonant, the second determines if a number is positive, negative, or zero using an else if ladder, and the third calculates an electricity bill based on unit consumption with specified rates for different ranges. Each program includes the necessary code and conditions for execution. The programs demonstrate basic conditional statements and user input handling in C.

Uploaded by

boddanaomkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C PROGRAMS

WEEK 3

PROGRAM-9
9. Write a C program to check whether an alphabet is Vowel or
Consonant
Conditions: Create a character type variable with name of
alphabet and take the value from the user. Use Conditional
Statements to solve.

Program

#include<stdio.h>
int main()
{
char c;
int lowercase_vowel, uppercase_vowel;
printf("Enter an alphabet: ");
scanf("%c", &c);
lowercase_vowel = (c=='a'||c=='e'||c=='i'||c=='o'||c=='u');
uppercase_vowel = (c=='A'||c=='E'||c=='I'||c=='O'||c=='U');
if (lowercase_vowel || uppercase_vowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
return 0;
}
PROGRAM-10
10. Write a C program to check whether number is positive,
negative or zero
Conditions:
➢ Create variable with name of number and the value will
be taken by user from console
➢ Create this c program code using else if ladder
statement.

Program
#include <stdio.h>
int main()
{
int number;
printf("Enter the number: ");
scanf("%d", &number);
if(number > 0)
printf("%d is positive.", number);
else if(number < 0)
printf("%d is negative.", number);
else
printf("%d is zero.", number);
return 0;
}
PROGRAM-11
11. Write a C program to calculate Electricity bill.
Conditions:
➢ For first 50 units – Rs. 3.50/unit
➢ For next 100 units – Rs. 4.00/unit
➢ For next 100 units – Rs. 5.20/unit
➢ For units above 250 – Rs. 6.50/unit

Program
#include<stdio.h>
int main()
{
float bill, units;
printf("Enter the units consumed=");
scanf("%f",&units);
if(units>=0 && units<=50)
{
bill=units*3.50;
printf("Electricity Bill=%0.2f Rupees",bill);
}
else if(units>50 && units<=100)
{
bill=50*3.50+(units-50)*4;
printf("Electricity Bill=%0.2f Rupees",bill);
}
else if(units>150 && units<=250)
{
bill=50*3.50+100*4+(units-150)*5.20;
printf("Electricity Bill=%0.2f Rupees",bill);
}
else if(units>250)
{
bill=50*3.50+100*4+100*5.20+(units-250)*6.50;
printf("Electricity Bill=%0.2f Rupees",bill);
}
else
printf("Please enter valid consumed units...");
return 0;
}

You might also like