Simple if:
Write a C Program to input Employee Id and basic pay of an employee and then print
Employee Id, HRA and Special allowance. Consider HRA is 20% of basic or Rs. 7000/ whichever
is less and Special allowance is 10% of basic pay whenever basic exceeds Rs 10000, Otherwise it
is 5% of basic pay.
if else:
Read in one character from the user (this may be 'Y', 'y', 'N', 'n'). If the character is 'Y' or 'y' display "YES". If the character is 'N' or 'n' display "NO". No other character will be provided as input.
https://www.hackerrank.com/challenges/30-conditional-statements/problem
- If is odd, print
Weird
- If is even and in the inclusive range of to , print
Not Weird
- If is even and in the inclusive range of to , print
Weird
- If is even and greater than , print
Not Weird
Units
|
Slab rate per unit
|
Less than 250
|
1.45 Rs
|
Less than 500
|
2.60 Rs.
|
Units
|
Slab rate per unit
|
Less than 500
|
3.00 Rs.
|
500 and above
|
5.00 Rs.
|
Each number on the telephone dial (except 0 and 1) corresponds to three alphabetic characters. Those correspondences are: 2 ABC 3 DEF 4 GHI 5 JKL 6 MNO 7 PRS 8 TUV 9 WXY Write a function to find the number dialled for given character. (10M)
#include<stdio.h>
void display(char ch)
{
if(ch=='A' || ch=='B' || ch=='C')
printf("2\n");
else if(ch=='D' || ch=='E' || ch=='F')
printf("3\n");
else if(ch=='G' || ch=='H' || ch=='I')
printf("4\n");
else if(ch=='K' || ch=='L' || ch=='M')
printf("5\n");
else if(ch=='N' || ch=='O' || ch=='P')
printf("6\n");
else if(ch=='Q' || ch=='R' || ch=='S')
printf("7\n");
else if(ch=='T' || ch=='U' || ch=='V')
printf("8\n");
else if(ch=='W' || ch=='X' || ch=='Y')
printf("9\n");
}
int main()
{
char ch;
printf("Enter a character:");
scanf("%c",&ch);
display(ch);
return 0;
}
A company decides to give bonus to all its employees on Diwali. A 5% bonus on salary is given to the male workers and 10% of bonus on salary to the female workers. Write a C function to read the salary and gender of the employee from a file. Calculate the bonus that must be given to the employee and display the salary that the employee will get.
Solution:
voidprintBonus()
{
float Salary,bonus;
char gender;
FILE *fp;
fp = fopen("Salary.txt","r");
scanf("%f %c",&Salary,&gender);
fclose(fp);
if(gender=='f'|| gender =='F')
bonus = 0.1*salary;
else
bonus = 0.05*salary;
printf("The Bonus: %f",bonus);
}
4) Design a flowchart to calculate the custom duty based on the following: Assume that imported goods from foreign countries are classified into 4 categories for imposing custom duty % of custom duty
Category on value of growth
1 10
2 15
3 17.5
4 25
- If the book is returned on or before the expected return date, no fine will be charged (i.e.: .
- If the book is returned after the expected return day but still within the same calendar month and year as the expected return date, .
- If the book is returned after the expected return month but still within the same calendar year as the expected return date, the .
- If the book is returned after the calendar year in which it was expected, there is a fixed fine of .
Month | Total days |
---|---|
January, March, May, July, August, October, December | 31 days |
February | 28/29 days |
April, June, September, November | 30 days |
#include <stdio.h>
int main() {
char operator;
double n1, n2;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operator);
printf("Enter two operands: ");
scanf("%lf %lf",&n1, &n2);
switch(operator)
{
case '+':
printf("%.1lf + %.1lf = %.1lf",n1, n2, n1+n2);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf",n1, n2, n1-n2);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf",n1, n2, n1*n2);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf",n1, n2, n1/n2);
break;
// operator doesn't match any case constant +, -, *, /
default:
printf("Error! operator is not correct");
}
return 0;
}
C program to find maximum between two numbers using switch case
Problem Comprehension:
condition 1: if endingHoursis equal to startingHours then
endingMinutes
must be >startingMinutes.
Ex: 15:10 and 15: 30
then answer=endingMinutes – startingMinutes = 30-10 = 20 minutes
· condition 2: if endingHours>startingHours
Ex: 15:10 and 18: 05 then
if the time is 15:10 then after 50 minutes it will be 16:00 ...60-startingMinutes
now find the difference between 16:00 and 18:00 that is 2 hours i.e endingHours-(staringHours+1)
add 5 minutes in 18:05
so, formula= (endingHours-(staringHours+1))*60+(60-startingMinutes)+endingMinutes
Q
Q) Meghana was filling application form for the job of Assistant professor in KLU.
The application requires the age of Meghana as on 08/2021.
If Meghana is born on 02/2005. What is the age in years she needs to fill in application form.
No comments:
Post a Comment