You are on page 1of 11

Assignment 3

1. #include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
main()
{
int num;
printf("Enter a number to check its divisibility by 4: ");
scanf("%d",&num);
if(num%4==0)
printf("\nThe number %d is divisible by 4.",num);
else
printf("The number is not divisibe by 4.");
getch();
}

2. #include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>

main()
{
int n, reverse = 0;
printf("Enter a number to reverse\n");
scanf("%d",&n);
while (n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
printf("Reverse of entered number is = %d\n", reverse);

3. #include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
main()
{
int year;
printf("Enter any year: ");
scanf("%d",&year);
if(((year%4==0)&&(year%100!=0))||(year%400==0))
printf("The year %d is a leap year",year);
else
printf("The year %d is not aleap year",year);
}

4. #include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>

int main()
{
int a, b, c;
printf("Enter the values of the sides of the triangle: \n");
scanf("%d %d %d", &a, &b, &c);

if(a+b>c&&a+c>b&&b+c>a)
{
if (a == b && b == c)
{
printf("Equilateral Triangle. \n");
}
else if (a == b || b == c || a == c)
{
printf("Isosceles Triangle. \n");
}
else
printf("Scalene Triangle. \n");
}
else
{printf("Triangle formation is not possible. \n");}
getch();
}

5. #include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
main()
{
int day;
printf("Enter the day of the week numerically: \n ");
scanf("%d",&day);
switch(day)
{
case 1:printf("The day is Sunday");
break;
case 2:printf("The day is Monday");
break;
case 3:printf("The day is Tuesday");
break;
case 4:printf("The day is Wednesday");

break;
case 5:printf("The day is Thursday");
break;
case 6:printf("The day is Friday");
break;
case 7:printf("The day is Saturday");
break;
default:printf("Invalid Entry");
}
}

6. #include<stdio.h>
main()
{
int year;
printf("Enter any year: ");
scanf("%d",&year);
if(((year%4==0)&&(year%100!=0))||(year%400==0))
printf("The number of days in this year are %d",366);
else
printf("The number of days in this year are %d",365);
}

7. #include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
main()
{
char ch;
printf("Enter an alphabet in upper/lower case to convert it to a different case: ");
scanf("%c",&ch);
if(islower(ch))

{
ch=toupper(ch);
printf("The alphabet is: %c ",ch);
}
else
{
ch=tolower(ch);
printf("The alphabet is: %c ",ch);
}
}

8. #include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
main()
{
char ch;
printf("\nEnter a character to see what category it stands in: ");
scanf("%c",&ch);
{
if((ch>64&&ch<91)||(ch>96&&ch<122))
printf("\nYou have entered an alphabet.");
else if((ch>127&&ch<256)||(ch>32&&ch<48))
printf("\nYou have entered a special character.");
else if(ch>47&&ch<58)
printf("\nYou have entered an Integral Value.");
else
printf("\nCharacter wasn't recognised.");
}
getch();
}

9. #include <stdio.h>
#include <conio.h>

#include <math.h>
#include <stdlib.h>
#include <ctype.h>
main()
{
char vowel;
printf("Enter a vowel: ");
scanf("%c",&vowel);
if(vowel=='a'||vowel=='e'||vowel=='i'||vowel=='o'||vowel=='u')
{
if(islower(vowel))
printf("The vowel is in lower case");
else
printf("The vowel is in Upper case");
}
else
printf("Character entered is not a vowel.");
getch();
}

10. #include <stdio.h>


#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
main()
{
int num;
printf("enter a number: ");
scanf("%d",&num);
if(num%2==0)
printf("The number you entered is even.");
else
printf("The number you entered is odd.");
}

11. #include <stdio.h>


#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>

main()
{
float det,root1,root2,a,b,c,real,imaginary;

printf("Enter the values of a,b and c for the equation ");


printf("\nax^2+bx+c : ");
scanf("%f%f%f",&a,&b,&c);
det=pow(b,2)-(4*a*c);

if(det>0)
{
printf("\nThe roots of this equation are: ");
root1 = (-b + (sqrt(det)))/(2*a);
root2 = (-b - (sqrt(det)))/(2*a);
printf("Roots are: %f and %f",root1 , root2);
}

else if (det==0)
printf("Both the roots are real and equal. The root is : %d",-b/(2*a));

else
{
real= -b/(2*a);
imaginary= sqrt(-det)/(2*a);
printf("Roots are: %.2f+%.2fi and %.2f-%.2fi", real, imaginary, real, imaginary);
}

getch();
}

12. #include<stdio.h>
#include<conio.h>
main()
{
int num1,num2,num3,min;
printf("Enter three numbers to check for the greatest amongst them : ");
scanf("%d%d%d",&num1,&num2,&num3);
if(num1<num2&&num1<num3)
min=num1;
else if(num2<num1&&num2<num3)
min=num2;
else
min=num3;
printf("The smallest number is: %d",min);
getch();
}

13. #include <stdio.h>


#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>

main()
{
int choice;
char ch;
float r,a,b,c,s,area,len,bre;

printf("------------AREA CALCULATOR MENU---------------");


printf("\n1. Circle");
printf("\n2. Triangle");
printf("\n3. Rectangle");
printf("\nEnter your choice : ");
scanf("%d",&choice);

switch(choice)
{
case 1:
printf("Enter the radius of the circle: ");
scanf("%f",&r);
area = 3.141*r*r;
printf("The Area is %.2f",area);

break;

case 2:
printf("Enter the sides of the triangle : ");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2.0;
area=sqrt(s*(s-a)*(s-c)*(s-b));
printf("The Area is %.2f",area);
break;

case 3:
printf("Enter the length and breadth of the rectangle : ");
scanf("%f%f",&len,&bre);
area = len*bre;
printf("The Area is %.2f",area);
break;

default: printf("Wrong choice entered!!");


}
getch();

*************************************************************************************

You might also like