You are on page 1of 6

C program to check the equivalence of two numbers

Aim:
Write a C program to check whether the given two numbers are equal or not.

Algorithm:
Step1: Start
Step2: Read two numbers
Step3: if (a==b) then
Step4: Print Given numbers are equal
Step5: else Print Given numbers are not equal
Step6: Stop

Sample Input and Output:


Enter 2 numbers
55
Given numbers are equal

Result:
Thus the program has been executed successfully.

C program to calculate Electricity bill


Aim:
Write a C program to calculate Electricity bill for the given customer.

Algorithm:
Step1: Start
Step 2: Enter Customer name
Step 3: Read no. of units
Step 4: Calculate
if (unit<=100)
amount=units*4;
else if (units>100 && units<=300)
amount=units*4.5;
else if (units>300 && units<=500)
amount=units*4.75;
else
amount=units*5;
Step 5: Print customer name and amount
Step 6: Stop

Sample Input and Output:


Enter Customer name and number of units
John 250

Electricity Bill:
Name: John
Amount: Rs.1125

Result:
Thus the program has been executed successfully.

C program to check the number is positive/negative odd or even (using Nested if)
Aim:
Write a C program to check whether the given number is positive/negative odd or even.

Algorithm:
Step 1: Start
Step 2: Read a number
Step 3: If(a>0) then
Step 4: If(a%2==0) then
Step 5: Print the given number is positive even
Step 6: Else Print the given number is positive odd
Step7: Else
Step 8: If(a%2==0) then
Step 9: Print the given number is negative even
Step10: Else Print the given number is negative odd
Step11: Stop

Sample input and output:


Enter a number
15
The given number is positive odd

Result:
Thus the program has been executed successfully.

C program to convert Seconds into 1.Minutes 2.Hours 3.Days (using switch)


Aim:
Write a C program to convert Seconds into 1.Minutes 2.Hours 3.Days

Algorithm:
Step1: Start
Step 2: Read no. of seconds
Step 3: Print Seconds into
1.Minutes
2. hours
3.days
Step 4: read any choice
Step 5: calculate
switch(ch)
{
case 1:
mins= seconds / 60;
printf(minutes:%d,mins);

break;
case 2:
hrs = seconds / (60*60);
printf(hours:%d,hrs);
break;
case 3:
days = seconds / (24*60*60);
printf(days:%d,days);
break;
default: print pls try again
Step 6: Stop

Sample Input and Output:


Enter no. of seconds
12345
Seconds into
1.Minutes
2. hours
3.days

Minutes: 205
Result:
Thus the program has been executed successfully.

C program to verify the given number is palindrome or not (using while)


Aim:
Write a C program to verify the given number is palindrome or not

Algorithm:
Step1: Start
Step 2: Enter a number
Step 3:
rev=0, t=n;
while(t!=0)
{
rem=t%10;
rev=rev*10+rem;
t/=10;
}
/* Checking if number entered by user and it's reverse number is equal. */
if(rev==n)
printf("%d is a palindrome.",n);
else
printf("%d is not a palindrome.",n);
Step 4: stop

Sample input and output:


Enter a number
121
121 is palindrome

Result:
Thus the program has been executed successfully.

You might also like