LAB-4-ASSIGNMENT-2023103623
1. Write a C program to enter the marks of students in 5 subjects and calculate the total, average and
display the grades obtained by the student.
CODE-
//Program to enter the marks of students in 5 subjects and calculate the total, average and display the
grades obtained by the student.
#include<stdio.h>
void main()
{
int a,b,c,d,e,f,g=0;
int total,avg=0,grade;
printf("ENTER SUBJECT 1 MARK\n");
scanf("%d",&a);
printf("ENTER SUBJECT 2 MARK\n");
scanf("%d",&b);
printf("ENTER SUBJECT 3 MARK\n");
scanf("%d",&c);
printf("ENTER SUBJECT 4 MARK\n");
scanf("%d",&d);
printf("ENTER SUBJECT 5 MARK\n");
scanf("%d",&e);
printf("Subjects Mark\n");
printf("SUBJECT 1 %d\n",a);
printf("SUBJECT 2 %d\n",b);
printf("SUBJECT 3 %d\n",c);
printf("SUBJECT 4 %d\n",d);
printf("SUBJECT 5 %d\n",e);
total=a+b+c+d+e;
avg=total/5;
printf("\t Total is %d\n",total);
printf("\t Average is %d\n",avg);
if(total>=400 && total<=500)
printf("\t Grade is A");
else if(total>=300 && total<400)
printf("\t Grade is B");
else if(total>=200 && total<300)
printf("\t Grade is C");
else if(total>=100 && total<200)
printf("\t Grade is D");
else
printf("\t FAIL \n");
}
2. A company decides to give bonus to its employees on account of Diwali. A 5% bonus is given to
the male workers and 10% bonus on salary to the female workers. Write a C program to enter the
salary and sex of the employee. If the salary of the employee is less than Rs. 10,000/- then the
employee gets an extra 2% bonus on salary. Calculate the bonus that has to be given to the employee
and display the salary that the employee will get.
CODE-
//Program to enter the salary and sex of the employee.
#include<stdio.h>
void main()
{
long int bonus,sal;
char gend,M,F;
printf("ENTER YOUR SALARY: \n");
scanf("%ld",&sal);
printf("ENTER YOUR GENDER EITHER MALE(M) OR FEMALE(F)\n");
scanf(" %c",&gend);
if(sal<10000)
{
if(gend=='M')
{
printf("THE EMPLOYEE IS A MALE");
bonus=(sal + (sal*5)/100 + (sal*2)/100);
}
if(gend=='F')
{
printf("THE EMPLOYEE IS A FEMALE");
bonus=(sal + (sal*10)/100 + (sal*2)/100);
}
}
else
{
if(gend=='M')
{
printf("THE EMPLOYEE IS A MALE");
bonus=(sal +( (sal*5)/100));
}
if(gend=='F')
{
printf("THE EMPLOYEE IS A FEMALE");
bonus=(sal +( (sal*10)/100));
}
}
printf("\n THE SALARY OF THE EMPLOYEE WITH BONUS: %ld",bonus);
3. Write a C program to calculate the tax, given the following conditions:
· If income is less than 1,50,000 then no tax
· If taxable income is in the range 1,50,001 – 3,00,000 then charge 10% tax
· If taxable income is in the range 3,00,001 – 5,00,000 then charge 20% tax
· If taxable income is above 5,00,001 then charge 30% tax
CODE-
//Program to calculate the tax.
#include<stdio.h>
void main()
{
long int t,i;
printf("ENTER YOUR INCOME:\n");
scanf("%ld",&i);
if(i<=150000)
printf("\t Tax is Zero ");
else if(i>150000 && i<=300000)
t=(i*0.1);
printf("\t Tax is 10% which is %ld",t);
else if(i>300000 && i<=500000)
t=(i*0.2);
printf("\t Tax is 20% which is %ld",t);
else
t=(i*0.3);
printf("\t Tax is 30% which is %ld",t);
}
4. Write a C program to determine whether the entered character is vowel or not.
CODE-
//Program to determine whether the entered character is vowel or not.
#include<stdio.h>
void main()
{
char v;
printf("ENTER AN ALPHABET: \n");
scanf("%c",&v);
switch(v)
{
case'a':
case'e':
case'i':
case'o':
case'u':
case'A':
case'E':
case'I':
case'O':
case'U':
{
printf("THE ALPHABET ENTERED IS A VOWEL");
break;
}
default:
printf("THE ALPHABET ENTERED IS A CONSONANT");
}
}
5. Write a C program to enter a number between 1 and 7 and display the corresponding day of the
week.
CODE-
//Program to enter a number between 1 and 7 and display the corresponding day of the week.
#include<stdio.h>
void main()
{
int d;
printf("ENTER A NUMBER BETWEEN 1 TO 7: \n");
scanf("%d",&d);
switch(d)
{
case 1:
{
printf("IT IS A SUNDAY");
break;
}
case 2:
{
printf("IT IS A MONDAY");
break;
}
case 3:
{
printf("IT IS A TUESDAY");
break;
}
case 4:
{
printf("IT IS A WEDNESDAY");
break;
}
case 5:
{
printf("IT IS A THURSDAY");
break;
}
case 6:
{
printf("IT IS A FRIDAY");
break;
}
case 7:
{
printf("IT IS A SATURDAY");
break;
}
default:
printf("INVALID");
}
}
6. Write a C program to accept any number between 1 and 10 and print whether it is odd or even.
CODE-
//Program to accept any number between 1 and 10 and print whether it is odd or even
#include<stdio.h>
void main()
{
int d;
printf("ENTER A NUMBER BETWEEN 1 TO 10: \n");
scanf("%d",&d);
switch(d)
{
case 1:
case 3:
case 5:
case 7:
case 9:
{
printf("IT IS AN ODD NUMBER");
break;
}
case 2:
case 4:
case 6:
case 8:
case 10:
{
printf("IT IS AN EVEN NUMBER");
break;
}
default:
printf("INVALID");
}
}
7. Write a C program to display the grades.
CODE-
//Program to display the grades.
#include<stdio.h>
void main()
{
int d;
printf("ENTER YOUR SCORE FOR 1 SUBJECT : \n");
scanf("%d",&d);
d=(d/10);
switch(d)
{
case 10:
case 9:
{
printf("YOU GOT O GRADE");
break;
}
case 8:
{
printf("YOU GOT A GRADE");
break;
}
case 7:
{
printf("YOU GOT B GRADE");
break;
}
case 6:
{
printf("YOU GOT C GRADE");
break;
}
case 5:
{
printf("YOU GOT D GRADE");
break;
}
default:
printf("FAIL");
}
}
8. Write a C program to read the month of the year as an integer and display the name of the month.
CODE-
//Program to enter a number between 1 and 7 and display the corresponding day of the week.
#include<stdio.h>
void main()
{
int d;
printf("ENTER A NUMBER BETWEEN 1 TO 12: \n");
scanf("%d",&d);
switch(d)
{
case 1:
{
printf("IT IS JANUARY");
break;
}
case 2:
{
printf("IT IS FEBRUARY");
break;
}
case 3:
{
printf("IT IS MARCH");
break;
}
case 4:
{
printf("IT IS APRIL");
break;
}
case 5:
{
printf("IT IS MAY");
break;
}
case 6:
{
printf("IT IS JUNE");
break;
}
case 7:
{
printf("IT IS JULY");
break;
}
case 8:
{
printf("IT IS AUGUST");
break;
}
case 9:
{
printf("IT IS SEPTEMBER");
break;
}
case 10:
{
printf("IT IS OCTOBER");
break;
}
case 11:
{
printf("IT IS NOVEMBER");
break;
}
case 12:
{
printf("IT IS DECEMBER");
break;
}
default:
printf("INVALID");
}
}
---------------------------------------------------------------THE END---------------------------------------------------------