Tanti Technology

My photo
Bangalore, karnataka, India
Multi-platform UNIX systems consultant and administrator in mutualized and virtualized environments I have 4.5+ years experience in AIX system Administration field. This site will be helpful for system administrator in their day to day activities.Your comments on posts are welcome.This blog is all about IBM AIX Unix flavour. This blog will be used by System admins who will be using AIX in their work life. It can also be used for those newbies who want to get certifications in AIX Administration. This blog will be updated frequently to help the system admins and other new learners. DISCLAIMER: Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility. If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.

Monday 4 July 2011

C program-2

1 ./* Write a C program to find the area of a triangle, given three sides*/

#include
#include

main()
{
int s, a, b, c, area;
clrscr();

printf("Enter the values of a,b and c\n");
scanf ("%d %d %d", &a, &b, &c);

/* compute s*/

s = (a + b + c) / 2;

area = sqrt ( s * (s-a) * (s-b) * (s-c));

printf ("Area of a triangale = %d\n", area);
}
/*-----------------------------
Output

Enter the values of a,b and c
3
4
5
Area of a triangale = 6
------------------------------*/


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



2. /* Write a C program to find the area of a circl, given the adius*/

#include
#include
#define PI 3.142

main()
{
float radius, area;
clrscr();

printf("Enter the radius of a circle\n");
scanf ("%f", &radius);

area = PI * pow (radius,2);

printf ("Area of a circle = %5.2f\n", area);
}
/*-----------------------------
Output

RUN1
Enter the radius of a circle
3.2
Area of a circle = 32.17

RUN 2
Enter the radius of a circle
6
Area of a circle = 113.11

------------------------------*/


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


3. /* Write a C program to find the simple interest , given principle, *
* rate of interest and times*/

#include

main()
{

float p, r, si;
int t;

clrscr();

printf("Enter the values of p,r and t\n");
scanf ("%f %f %d", &p, &r, &t);

si = (p * r * t)/ 100.0;
printf ("Amount = Rs. %5.2f\n", p);
printf ("Rate = Rs. %5.2f%\n", r);
printf ("Time = %d years\n", t);
printf ("Simple interest = %5.2f\n", si);
}
/*-----------------------------
Output
Enter the values of p,r and t
2000
8
3
Amount = Rs. 2000.00
Rate = Rs. 8.00%
Time = 3 years
Simple interest = 480.00

------------------------------*/

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


4. /* Write a C program to check whether a given integer is odd or even*/

#include

main()
{
int ival, remainder;
clrscr();

printf("Enter an integer :");
scanf ("%d", &ival);

remainder = ival % 2;

if (remainder == 0)
printf ("%d, is an even integer\n", ival);
else
printf ("%d, is an odd integer\n", ival);

}
/*-----------------------------
Output

RUN1

Enter an integer :13
13, is an odd integer

RUN2
Enter an integer :24
24, is an even integer

---------------------------------*/

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


5. /* Write a C program to check whether a given integer *
* number is positive or negative*/

#include

main()
{
int number;
clrscr();

printf("Enter a number\n");
scanf ("%d", &number);

if (number > 0)
printf ("%d, is a positive number\n", number);
else
printf ("%d, is a negative number\n", number);

}
/*-----------------------------
Output
Enter a number
-5
-5, is a negative number

RUN2
Enter a number
89
89, is a positive number
------------------------------*/

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

No comments:

Post a Comment