0% found this document useful (0 votes)
5 views

Lab Assignment 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab Assignment 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Name - Tanmay Shrivastava

Course-BTech(CSE)
Roll No.-24155589

Day 5(Lab Assignments)


Question 1)WAP to find the largest between two numbers.
#include <stdio.h>
int main()
INPUT:
{
int a,b; Enter the first number=12
printf("Enter the first number:"); Enter the second number=17
scanf("%d",&a);
printf("Enter the second number:");
scanf("%d",&b);
if(a>b)
OUTPUT:
{
printf("Largest number=%d",a); Largest number=17
}
else
{
printf("Largest Number=%d",b);
}
return 0;
}
Question 2)WAP to read an alphabet from the user and convert it into uppercase if the entered alphabet
is in lowercase, otherwise display an appropriate message.

#include <stdio.h> INPUT:


int main() Enter the alphabet=a
{
char c;
printf("Enter the alphabet=");
scanf("%c",&c);
if(c>='a'&&c<='z') OUTPUT:
{ Uppercase is A
c=c-32;
printf("Uppercase is %c",c);
}
else
{
print("It is in uppercase");
}
return 0;
}
Question 3)WAP to read a character from the user and test whether it is a vowel or consonant or not an
alphabet.
#include <stdio.h>
int main()
{ INPUT:
char c; Enter the character=A
printf("Enter the character=");
scanf("%c",&c);
if(c=="A"||c=='E'||c=='I'||c=='O'||c=='U'||c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
{
printf("The entered character is a vowel"); OUTPUT:
} The entered character is a
else
{
vowel
printf("The entered character is a consonant");
}
return 0;
}
Question 4)WAP to determine whether a year entered through the keyboard is a leap year or not.
#include <stdio.h>
int main()
{
int a;
printf("Enter the year=");
scanf("%d",&a);
if(a%100==0) INPUT:
{
if(a%400==0)
Enter the year=2000
{
printf("%d is a centinnial leap year",a);
}
else
{
printf("%d is a centinnial non-leap year",a);
}
}
else
{ OUTPUT:
if(a%4==0)
{ 2000 is a centinnial leap year
printf("%d is a non centinnial leap year",a);
}
else
{
printf("%d is a non centinnial non-leap year",a);
}
}
return 0;
}
Question 5)WAP to find the roots of a quadratic equation ax2+bx+c=0 using an if-else statement.
#include <math.h>
#include <stdio.h>
int main()
{
double a, b, c, discriminant,R1,R2;
printf("Enter a=");
scanf("%lf",&a); INPUT:
printf("Enter b="); Enter a=1
scanf("%lf",&b);
printf("Enter c="); Enter b=5
scanf("%lf",&c);
discriminant = b*b-4*a*c;
Enter c=6
if (discriminant > 0)
{
R1 = (-b + sqrt(discriminant)) / (2 * a);
R2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Roots are real and distinct and are %.2lf and %.2lf", R1, R2); OUTPUT:
}
else if (discriminant == 0)
The roots are real and distinct and
{ are -2.00 and -3.00
R1 = R2 = -b / (2 * a);
printf("The roots are real and equal and is %.2lf", R1);
}
else
{
printf("Roots are imaginary");
}
return 0;
Question 6)WAP to display the grade system of KIIT University based on total marks secured by a student in asemester. Assume marks are integer values. Use multiple if-else
statements.
The grade is calculated is as follows:
Marks Grade #include <stdio.h>
90 to 100 O int main()
{
80 to 89 E int marks;
70 to 79 A printf("Enter the marks scored by student=");
60 to 69 B scanf("%d",&marks);
if(marks>90&&marks<100)
INPUT:
50 to 59 C
40 to 49 D
{
printf("The grade received is O"); Enter the marks scored by student=76
}
< 40 F else if(marks<89&&marks<80)
{
printf("The grade received is E");
}
else if(marks<79&&marks>70)
{
printf("The grade received is A");
}
else if(marks<69&&marks>60) OUTPUT:
{

}
printf("The grade received is B"); The grade received is A
else if(marks<59&&marks>50)
{
printf("The grade received is C");
}
else if(marks<49&&marks>40)
{
printf("The grade received is D");
}
else
{
printf("The grade received is F");
}
return 0;
}

You might also like