Saturday, October 12, 2013

WAP to input 3 sides of triangle and check whether it is valid or not


#include<conio.h>
#include<stdio.h>
#include<math.h>
int main()
{
float a,b,c,s,A;
printf("\n enter the value of the sides of the triangle:");
scanf("%f%f%f",&a,&b,&c);
if( (a+b>c) && (b+c>a) && (a+c>b) )
{
s=(a+b+c)/2;
A=sqrt(s*(s-a)*(s-b)*(s-c));
printf("\n the triangle is valid");
printf("\n the area of the triangle is:%f",A);
}
else
printf("\n the triangle is not valid");
getch();
return 0;
}

Write a C program to check whether entered year is leap year or not


#include <stdio.h>
int main()
{
int year;
printf("Enter a year to check if it is a leap year\n");
scanf("%d", &year);
if ( year%400 == 0)
printf("%d is a leap year.\n", year);

else if ( year%100 == 0)
printf("%d is not a leap year.\n", year);

else if ( year%4 == 0 )
printf("%d is a leap year.\n", year);

else
printf("%d is not a leap year.\n", year);
return 0;
}

Write a C program to check whether input alphabet is a vowel or not

#include <stdio.h>
int main()
{
char ch;
printf("Enter a character\n");
scanf("%c", &ch);
if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' || ch == 'u' ||ch == 'U')
printf("%c is a vowel.\n", ch);
else
printf("%c is not a vowel.\n", ch);
return 0;
}

Program to check and print days of week


#include<stdio.h>
#include<conio.h>
int main( )
{
 int dayno;
 clrscr( );
 printf("\n Enter the day number:");
 scanf("%d",&dayno);
 if(dayno==1)
 printf("The day is Monday");
 else if(dayno==2)
 printf("The day is Tuesday");
 else if(dayno==3)
 printf("The day is Wednesday");
 else if(dayno==4)
 printf("The day is Thursday");
 else if(dayno==5)
 printf("The day is Friday");
 else if(dayno==6)
 printf("The day is Saturday");
 else if(dayno==7)
 printf("The day is Sunday");
 else
 printf("Wrong day number");
getch();
return 0;
}

WAP to find the simple interest if principle amount is less than 10000 else find the compound interest


#include<conio.h>
#include<stdio.h>
#include<math.h>
int main()
{
float p=0.0,r=0.0,si=0.0,ci=0.0;
int t=0;
printf("\n enter the principal,rate and time:");
scanf("%f%f%d",&p,&r,&t);
if(p<10000)
{
si=p*r*t/100;
printf("\n the simple interest is :%f",si);
}
else
{
ci=p*pow(1+(r/100),t);
printf("\n the compound interest is :%f",ci);
}
getch();
return 0;
}