Assignment 3
Problem 1: WAP that checks whether the two numbers entered by the user are equal or not.
sol.
#include<stdio.h>
main()
{
int a,b;
printf("enter the number a = ");
scanf("%d",&a);
printf("enter the number b = ");
scanf("%d",&b);
if (a==b)
{
printf("The entered number is equal");
}
else
{
printf("The entered number is not equal");
}
return 0;
}
Problem 2: WAP to find the greatest of three numbers.
sol.
#include<stdio.h>
main()
{
int a,b,c;
printf("enter the value of a: ");
scanf("%d",&a);
printf("enter the value of b: ");
scanf("%d",&b);
printf("enter the value of c: ");
scanf("%d",&c);
if (a>b)
{
if (a>c)
{
printf("The greatest number is %d",a);
}
else
{
printf("The greatest number is %d",c);
}
}
else
{
if ( b>c)
{
printf("The greatest number is %d",b);
}
else
{
printf("The greatest number is %d",c);
}
}
return 0;
}
Problem 3: WAP that finds whether a given number is even or odd.
sol.
#include<stdio.h>
main()
{
int a;
printf("enter the number: ");
scanf("%d",&a);
if (a%2==0)
{
printf("The number enter is even");
}
else
{
printf("The number enter is odd");
}
return 0;
}
Problem 4: WAP that tells whether a given year is a leap year or not.
sol.
#include<stdio.h>
main()
{
int a;
printf("Enter the year: ");
scanf("%d",&a);
if (a%100==0)
{
if (a%400==0)
{
printf("This year is leap year ");
}
else
{
printf("This year is not a leap year ");
}
}
else
{
if (a%4==0)
{
printf("This year is leap year ");
}
else
{
printf("This year is not leap year");
}
}
return 0;
}
Problem 5: WAP that accepts marks of five subjects and finds percentage and prints grades according to the following criteria:
Between 90-100%-----Print ‘A’
80-90%-----------------Print ‘B’
60-80%-----------------Print ‘C’
Below 60%-------------Print ‘D’
sol.
#include<stdio.h>
#include<math.h>
main()
{
float art, computer, english, bio, math, total, percentage;
// Input marks for each subject
printf("Enter marks obtained in Art: ");
scanf("%f", &art);
printf("Enter marks obtained in Bio: ");
scanf("%f", &bio);
printf("Enter marks obtained in Math: ");
scanf("%f", &math);
printf("Enter marks obtained in Computer: ");
scanf("%f", &computer);
printf("Enter marks obtained in English: ");
scanf("%f", &english);
// Calculate sum and percentage of marks
total = art + computer + math + english + bio;
percentage = (total / 500) * 100;
// Display the result
printf("Sum of Marks: %f \n", total);
printf("Percentage: %f \n", percentage);
if (percentage>=90)
{
printf("the grade is :'A' ");
}
else if (percentage>=80)
{
printf("the grade is : 'B' ");
}
else if (percentage>=60)
{
printf("the grade is : 'C' ");
}
else
{
printf("the grade is : 'D' ");
}
return 0;
}
0 comments:
Post a Comment