8. Get the student details like name, dept, m1,m2,m3.
Find the average and grade of the student
(O, A, B, C). Using switch case convert the grade into O- Excellent, A- Good, B-Average, C-Fair
#include<stdio.h>
int main()
{
int m1,m2,m3,average=0;
char grade,name[50],dept[50];
printf("Enter name and department\n");
scanf("%s %s",&name,&dept);
printf("Enter the marks of three subjects\n");
scanf("%d %d %d",&m1,&m2,&m3);
average=(m1+m2+m3)/3;
printf("The average is %d\n",average);
if(average>=85)
grade='O';
else if(average>=70)
grade='A';
else if(average>=60)
grade='B';
else if(average<60)
grade='C';
else
printf("Invalid Data");
switch(grade)
{
case 'O':
printf("Excellent");
break;
case 'A':
printf("Good");
break;
case 'B':
printf("Average");
break;
case 'C':
printf("Fair ");
break;
default:
printf("Invalid Data");
}
return 0;
}
9.Check whether the required amount can be withdrawn based on the available amount
#include<stdio.h>
int main()
{
int total_amount,withdraw;
printf("Enter the total amount");
scanf("%d",&total_amount);
printf("Enter the withdrawal amount");
scanf("%d",&withdraw);
if(withdraw>(total_amount-500))
printf(" INSUFFICENT BALANCE\n");
else
{
total_amount=total_amount-withdraw;
printf(" PLEASE COLLECT CASH\n");
printf("YOUR CURRENT BALANCE IS %d", total_amount);
}
return 0;
10.Menu-driven program to find the area of different shapes
#include<stdio.h>
int main()
{
float area,a,l,b,r,h;
int choice;
printf("Choose the shape\n\n");
printf("1.Square\n2.Rectangle\n3.Circle\n4.Triangle\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter the side:");
scanf("%f",&a);
area=a*a;
break;
case 2:
printf("\nEnter Length And Breadth Of Rectangle:");
scanf("%f %f",&l,&b);
area=l*b;
break;
case 3:
printf("\nEnter the radius:");
scanf("%f",&r);
area=3.14*r*r;
break;
case 4:
printf("\nEnter the base and height:");
scanf("%f %f",&b,&h);
area=0.5*b*h;
break;
default:
printf("Invalid input\n");
}
printf("The area is %f ",area);
return 0;
11. Write a program to get numbers from user until the user type “999”. Find the sum of even
numbers and odd numbers. Also calculate the count of odd numbers and even numbers.
#include <stdio.h>
#include<math.h>
int main()
{
int input,even=0,odd=0,evensum=0,oddsum=0;
while(1)
{
scanf("%d",&input);
if(input==999)
break;
if(input%2==0)
{
even++;
evensum+=input;
}
else
{
odd++;
oddsum+=input;
}
}
printf(" There are %d even numbers and the total even sum is %d\n",even,evensum);
printf(" There are %d odd numbers and the total odd sum is %d",odd,oddsum);
}
12.Write program to calculate the roots of a quadratic equation.
#include<stdio.h>
#include<math.h>
int main()
{
double a,b,c,d,root1,root2,realpart,imgpart;
printf("Enter a,b,c for a*x*x + b*x + c=0\n");
scanf("%lf %lf %lf",&a,&b,&c);
d=(b*b) - (4*a*c);
if(d>0)
{
root1=(-b + sqrt(d))/2*a;
root2=(-b - sqrt(d))/2*a;
printf("root 1= %.2lf \nroot 2= %.2lf",root1,root2);
}
else if(d==0)
{
root1=root2=-b/(2*a);
printf("root1 = root2 = %.2lf",root1);
}
else
{
realpart=-b/(2*a);
imgpart=sqrt(-d)/2*a;
printf("root 1= %.2lf + i%.2lf \nroot 2= %.2lf - i%.2lf",realpart,imgpart,realpart,imgpart);
}
13.(e) Full Pyramid:
#include<stdio.h>
int main()
{
int i,j,n;
scanf("%d",&n);
int space=n-1;
for(i=0;i<n;i++)
{
for(j=0;j<space;j++)
{
printf(" ");
}
for(j=0;j<=i;j++)
{
printf("* ");
}
printf("\n");
space--;
}
return 0;
}
13.(f) Inverted Pyramid
#include<stdio.h>
int main()
{
int i,j,n;
scanf("%d",&n);
int space=0;
for(i=n;i>0;i--)
{
for(j=0;j<space;j++)
{
printf(" ");
}
for(j=0;j<i;j++)
{
printf("* ");
}
printf("\n");
space++;
}
return 0;
}
13.(g) Hollow Pyramid
#include <stdio.h>
int main() {
int n, i, j;
printf("Enter number of lines: ");
scanf("%d", &n);
for(i = 1; i<=n; i++)
{
for(j = 1; j<=(n-i); j++)
{
printf(" ");
}
if(i == 1 || i == n)
{
for(j = 1; j<=i; j++)
{
printf("* ");
}
}
else
{
printf("*");
for(j = 1; j<=2*i-3; j++)
{
printf(" ");
}
printf("*");
}
printf("\n");
}
}
14. Check whether the given number if prime or composite.
#include <stdio.h>
#include<math.h>
int main()
{
int num,count=0,i;
printf("Enter the number:");
scanf("%d",&num);
for(i=1;i<=sqrt(num);i++)
{
if(num%i==0)
count++;
}
if(count==1)
printf("The number is a prime number");
else
printf("The number is a composite number");
}