You are on page 1of 6

ASSIGNMENT-2

1) 2ND LARGEST AMONG 3 NOS :

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a,b,c;
printf("Enter 1st number: ");
scanf("%d",&a);
printf("Enter 2nd number: ");
scanf("%d",&b);
printf("Enter 3rd number: ");
scanf("%d",&c);
if(a>b&&a>c)
if(b>c)
printf("%d is the 2nd largest number.",b);
else
printf("%d is the 2nd largest number.",c);
else if(b>a&&b>c)
if(a>c)
printf("%d is the 2nd largest number.",a);
else
printf("%d is the 2nd largest number.",c);
else
if(a>b)
printf("%d is the 2nd largest number.",a);
else
printf("%d is the 2nd largest number.",b);
getch();
}

2) AREA AND CIRCUMFERENCE OF A CIRCLE :

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
double r;
printf("Enter the radius of the circle : ");
scanf("%lf",&r);
printf("The area of the circle is : %lf units.\n",3.14*r*r);
printf("The circumference of the circle is : %lf units.",2*3.14*r);
getch();
}

3) AREA OF A TRIANGLE (base, height)

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
double b,h;
printf("Enter the base and height of the triangle : ");
scanf("%lf %lf",&b,&h);
printf("The area of the triangle is : %lf units.\n",0.5*b*h);
getch();
}

4) CONVERT TEMPERATURE IN CELCIUS TO FAHRENHEIT :

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
float t;
printf("Enter the temperature in celcius : ");
scanf("%f",&t);
printf("The temperature in fahrenheit is : %f",(t*9/5)+32);
getch();
}
5) SIMPLE INTEREST :

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
float p,n,r;
printf("Enter the principal amount : ");
scanf("%f",&p);
printf("Enter the time period : ");
scanf("%f",&n);
printf("Enter the rate of interest : ");
scanf("%f",&r);
printf("The simple interest is : %f. ",(p*n*r)/100);
getch();
}

6) VOWEL?

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
char a;
printf("Enter a character : ");
scanf("%s",&a);
switch(a)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("This is a vowel.");
break;
default :
printf("This is not a vowel.");
}
getch();
}

7) GETTING DIFFERENT DATA TYPES :

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a;
float b;
char c;
double d;
printf("Enter an integer :");
scanf("%d",&a);
printf("Enter a float :");
scanf("%f",&b);
printf("Enter a character :");
scanf("%s",&c);
printf("Enter a double :");
scanf("%Lf",&d);
getch();
}

8) ODD OR EVEN :

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a;
printf("Enter a number :");
scanf("%d",&a);
if(a%2==0)
printf("It is even.");
else
printf("It is odd.");
getch();
}

9) AVERAGE :

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int n,a,s=0;
printf("Enter the no.of numbers :");
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
printf("Enter number%d :",i);
scanf("%d",&a);
s+=a;
}
printf("The average of the given numbers is %f.",float(s)/n);
getch();
}

10) FACTORIAL :

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int n,f=1;
printf("Enter a number :");
scanf("%d",&n);
for(int i=1; i<=n; i++)
f*=i;
printf("The factorial of the given number is %d.",f);
getch();
}

You might also like