Posts

Showing posts from December, 2009

WAP to display the equation of a line in the form ax + by = c, for a=5, b=8, c=18.

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.14, page 22 #include <stdio.h> #define a 5
#define b 8
#define c 18 int main(void)
{
printf("\n\n"); printf("%dx  +  %dy  =  %d",a,b,c); printf("\n\n");
return 0;
}

WAP- The line joining the points (2,2) and (5,6) which lie on the circumference of the circle is the diameter of the circle. Write a program to compute the area of the circle.

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.13, page 22
#include <stdio.h>
#include <math.h>
#define PI 3.14
//point 1
#define x1 2
#define y1 2
//point 2
#define x2 5
#define y2 6
int main(void)
{int term1,term2,d,r;
float perim;

WAP- A point on the circumference of a circle whose center is (0,0) is (4,5). Write a program to computer perimeter and area of the circle.

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.12, page 22

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

//single-point control,
//as suggested by Code Complete 2

#define center_x 0
#define center_y 0

#define point_on_circle_x 4
#define point_on_circle_y 5

#define PI 3.14

int main(void)
{float radius=0.0, term1=0, term2=0;

WAP- Distance between two points (x1,y1) and (x2,y2) is governed by the following formula D=sqrt((x2-x1)^2 + (y2-y1)^2). Write a program to computer D given the coordinates of the points.

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.11, page 22 #include <stdio.h> //point 1
#define x1 5
#define y1 2 //point 2
#define x2 14
#define y2 7 int main(void)
{int term1, term2,D;
printf("\n\n"); term1=(x2-x1)*(x2-x1);
term2=(y2-y1)*(y2-y1); D=sqrt(term1+term2); printf("The distance between points (%d,%d) and (%d,%d) is %d",x1,y1, x2,y2, D); printf("\n\n");
return 0;
}

WAP- Area of a triangle is given by the formula A=sqrt(S(S-a)(S-b)(S-c)), where a, b and c are sides of the triangle and 2S=a+b+c. Write a program to compute the area of the triangle given the values of a, b and c.

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.10, page 22 #include <stdio.h>
#include <math.h> #define a 10
#define b 10
#define c 10 int main(void)
{float S,area;
printf("\n\n"); S=(a+b+c)/2;
area=sqrt(S*(S-a)*(S-b)*(S-c)); printf("For a=%d, b=%d, c=%d,\n",a,b,c);
printf("the area of triangle is %f",area); printf("\n\n");
return 0;
}

WAP- Relation between Celsius and Fahrenheit is governed by the formula F=(9C/5)+32. Write a program to convert the temperature

from Celsius to Fahrenheit, andfrom Fahrenheit to Celsius//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.9, page 21 #include <stdio.h> int main(void)
{float temp,fahren,celsius;
printf("\n\n"); printf("Enter the temperature : ");
scanf("%f", &temp); fahren=( (9*temp)/5 )+5;
celsius=( 5*(temp-32) )/9; printf("\n");
printf("1. %f Celsius      = %f Fahrenheit\n",temp, fahren);
printf("2. %f Fahrenheit   = %f Celsius",temp, celsius); printf("\n\n");
return 0;
}

WAP- Given the values of three variables a, b and c, write a program to compute and display the value of x, where x=a/(b-c)

Execute your program for the following values
a=250, b=85, c=25 a=300, b=70, c=70 Comment on the output in each case

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.8, page 21
#include <stdio.h>
#define a 300
#define b 70
#define c 70
int main(void)
{
printf("\n\n");
printf("For a=%d, b=%d, c=%d,\n",a,b,c);
printf("x is %d",a/(b-c));
printf("\n\n");

WAP- Given two integers 20 and 10, write a program that uses a function add() to add these two numbers and sub() to find the difference of these two numbers and then display the sum and difference in the following form:

20 + 10 = 30
20 – 10 = 10 //E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.7, page 21 #include <stdio.h> int add(int a, int b)
{return (a+b);
} int sub(int a, int b)
{return (a-b);
} #define A 20
#define B 10 int main(void)
{printf("\n\n"); printf("%d  +  %d  =  %d\n",A, B, add(A,B));
printf("%d  +  %d  =  %d",A,B,sub(A,B)); printf("\n\n");
return 0;
}

WAP to output the following multiplication table:

5 x 1 = 5
5 x 2 =10
5 x 3 = 15

5 x 10 = 50//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.6, page 21 #include <stdio.h> #define MUL 5 int main (void)
{int i;
printf("\n\n"); for (i=1;i<=10;i++)
    {printf("%d  *  %d  =  %d\n",MUL,i,(MUL*i));
    } printf("\n\n");
return 0;
}

WAP- Given the radius of a circle, write a program to compute and display its area. Use a symbolic constant to define the pi value and assume a suitable value for radius

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.5, page 21 #include <stdio.h> #define PI 3.142 int main(void)
{float radius,area; printf("\n\n"); printf("Enter radius of circle : ");
scanf("%f",&radius); area=PI*radius*radius; printf("Area of circle : %f",area); printf("\n\n");
return 0;
}

WAP that will print the following figure using suitable characters

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.4, page 21 #include <stdio.h> int main(void)
{printf("\n\n"); printf("**********          *********\n");
printf("**********          *********\n");
printf("**********>>------->*********\n");
printf("**********          *********\n");
printf("**********          *********"); printf("\n\n");
return 0;
}

WAP using one print statement to print the pattern of asterisks as shown below:

*
* *
* * *
* * * *
* * * * *//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.2, page 21 //E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.3, page 21 #include <stdio.h> int main(void)
{printf("\n\n"); printf("*\n*\t*\n*\t*\t*\n*\t*\t*\t*\n*\t*\t*\t*\t*"); printf("\n\n"); return 0;
}

WAP that will print your mailing address with border in the following form:

First line     : Name
Second line : Door No, Street
Third line    : City, PIN code //E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.2, page 21 #include<stdio.h> int main(void)
{printf("\n\n"); printf("**********************************\n");
printf("*Name            : Gopal Aggarwal*\n");
printf("*Door No, Street : 1234, Southall*\n");
printf("*City, PIN code  : London, 654321*\n");
printf("**********************************\n"); return 0;
}

Disclaimer

This is my personal blog where I share random thoughts, stuff for friends and family, opinions, reviews, technical stuff.

Prisoner's Dillemna Experiment- Copenhagen Summit 2009, And More

A lot has been going around. The problem of climate change, and deteriorating Earth is real, but I feel the efforts are misguided- It has happened before and is happening now.

Actions Speak Louder Than Words, Thoughts Or Emotions

Quite sometimes, we meet people who have the gift of gab- they talk pleasantly, confidently and often in our terms. But some of them may leave us feeling uneasy, or emotionally drained as if we have been talked into doing something that we didn't really want to, or having to pretend a lot while they're around. Or worse, they say something to us, and do another in reality.