Posts

Showing posts from 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.

Is MCA For You?

This is a guest post by Ankit Aggarwal, who’s also doing Masters in Computers Application (MCA),  from NIT Allahabad, while I'm from GNDU, Amritsar.

With almost a year over with my MCA at NIT Allahabad, I have lot of questions revolving around my head about the course. Master’s InOfIn Of Computer Application (MCA) is a course offered by various universities and colleges in India and eligibility is Bachelor’s degree in any background. I am probably the first person to write few negative things about the course I am in.:P

Reliance Does It Again- This Time Low Call Rates For All Indians

After handing almost every Indian with a mobile phone with its revolutionary Rupees 501/- scheme years ago, Reliance does it again.

This time with its bold offer of all calls (landline and mobile), local and STD at 50 Paise per minute- without any bonus cards or monthly rentals, and the tariff valid for lifetime. Lifetime in telecom circles means at least till 2021, and that’s a long time.

Even if one is not on Reliance, the other companies are already feeling the heat and have come out with unbelievable offers.

All I can say is thank you Reliance.

Tip For Google’s Data Appetite- Users Are Aware And They Don’t Want You To Store Online Tracks Like You Want To Create A Clone Of Them In 2050

It’s business after all, and some sort of data is necessary to run a successful business by noticing trends, predicting new demands and countering rivals’ products. But who’ll explain the fetish of this beloved company that is the lynchpin of the Internet community?

Thank You Way2SMS.com, For Giving Sense To Vodafone

Thank you way2sms.com and other net-to-cell phone SMS sites, for giving some sense to mobile operators like Vodafone.Now in the same Rs29/- pack they give local as well as national SMS messages. Couldn’t have happened without you.

Some Tips Regarding SSB Interview Call Letters

SSB Interview call letter is an important document, but it is quite possible that you may not receive the letter at all... It may happen at times, and you yourself need to be alert.

You should be getting it around 3-4 weeks before the Interview date. From my own experiences, and those of many aspirants whom I have interacted with, here are some tips:

Can Rationing The Electricity Be A Solution For The Time Being? Also, Subsidising CFL Bulbs?

“Rationing is the controlled distribution of resources and scarce goods or services. Rationing controls the size of the ration, one's allotted portion of the resources being distributed on a particular day or at a particular time.” Almost all of Punjab, and other areas of North India are experiencing power cuts on daily basis. Most of us have already adjusted our routine around those cuts. Those among us who can afford have installed generators at their place, but that’s not the solution for the rest of us.

Always Wanted To See Reverse Psychology And Herd Behavior In Action? Here You Go…

Image
Chattbir Zoo is located in Chandigarh, Punjab, India. Visiting it with my parents, I got to observe reverse psychology and some degree of herd behaviour.

There’s a small path that deviates from the main track of the zoo, and here there is a clear marker that says in red “NO ENTRY”.

Yes! Finally Won Against Hard CPU In Langres Map (Company Of Heroes: Opposing Fronts Skirmish Match)

Image
I am a regular player and this Langres map skirmish had me tied for weeks. Won vs Normal CPU after a few attempts, but vs Hard CPU, wow, got beaten up so many times.

Company Of Heroes: Opposing Fronts- A Skirmish Match Between Human And Artificial Intelligence Reveals Weaknesses In AI’s Armour

Image
There is an interesting and informative compilation on Current Methods to Create Human-Level Artificial Intelligence in Computer Simulations and Wargames (Google search). The opening page mentions that computers have difficulty thinking out of the box.

WAP to evaluate the following investment equation (C++)

V=P(1+r)n
and print the tables which would give the value of V for various combinations of the following values of P, r and n:
P: 1000, 2000, 3000, …, 10,000
r: 0.10, 0.11, 0.12, …, 0.19
n:1, 2, 3, …, 10
#include <iostream.h>
#include <math.h>
#include <conio.h>
int main(void)
{clrscr();

WAP to print the following output using for loops (C++)

1
22
333
4444
55555
…………
#include <iostream.h>
int main()
{int n;

Thoughts And Lessons In Software Development, By The Gurus

“In our desire to please everyone, it's very easy to end up being invisible or mediocre. Far better to please the right people.”, Seth Godin (link) “2004 study of four Army divisions that had just returned from tours in Iraq found that most leaders had strong technical and tactical skills. What set the best leaders apart was interpersonal skills.

C Compile Time Error- When Trying To Modify A const Variable

Image
Borland Turbo C++ Ver 3.0, run on Windows Vista, using DOSBox

Educating The (Young) Students May Offer A Long-Lasting Hope For Earth

“I am standing at the checkout counter of a supermarket, waiting for my turn, when I hear the excited cries of a young kid telling her dad not to take the polythene but use a bag…” I am pleasantly surprised and the hope that all is not lost got brighter.

Want To Republish From This Site? (License And Copyright Info)

Image
Legal

This work by Gopal Aggarwal is licensed under a Creative Commons Attribution-Noncommercial 2.5 India License.

Commercial
For commercial, kindly email me at gopal1035@gmail.com.

Most content on this site is my original work, and attributed to respective owners when otherwise.

Warm regards
Gopal

God Give Peace To My Country- Unity In Diversity

“If Sikhs get Khalistan, then they fight for Jattstan and Lubanastan and Ramdasiastan...

Sikhs, Hindus, and Muslims need to live with each other with peace my friend.

Separating ourselves [regarding some Sikhs demanding separate state] from India will not help in prosperity of Khalistan.

Indian Military- Becoming A Commissioned Officer– First-Hand Experiences, Tips And Suggested Reading For Aspirants

Image

Dream To Be A Military Officer In The Indian Armed Forces- How To Go About It? (Info For Freshers)

The basic outline for getting selected for training in various academies for commission is
Earning the right to SSB (Services Selection Board) Interview. This can be on the basis of written exams (like NDA, CDSE), educational qualifications (like BSc, BTech, Medical etc), or on the basis of NCC (National Cadet Corps) etc The SSB deals with the personality and intelligence. Its only responsibility is to thoroughly evaluate (interview is spread over five days) the psyche, intelligence and suitability of the candidate for a career in the Armed Forces, and give its opinion. There are a large number of centres spread all over the country (like Bhopal, Allahabad, Bangalore etc)

Going To The Bangalore SSB Interview For The First Time?

Image
(this is a travelogue from home to SSB, 5 day Interview, and back)
Contents:
Jalandhar to Bangalore Bangalore SSB Testing Procedure Suggested Reading

Interesting Historical Hand Pump - Water Pole at Shimla

Image
Shimla is an evergreen tourist place. Many of us might have visited more than once. As they say, Shimla is the place to be in summers for coolness, in winters to indulge in snow.

Well, besides the obvious attractions I suggest you check out surprises hidden along the station and Ridge.

You Want To Turn Off That Game, Believe Me, You Want To

Image
“A Fostoria (Ohio) man pleaded guilty Wednesday to two counts of involuntary manslaughter in connection to the drowning-deaths of his 10-month-old twins. On August 7, Gregg J. Kleinmark, 24, left his sons unattended in a bathtub for 30 minutes while he played a "computer game" three rooms away.” (link)

Not Getting Shot In The Face Repeatedly

Image
Fellow gamers must be laughing out loud, as they might see themselves in place of the “15 year old boy” :)

Image taken from the trailer of Battlefield Heroes game, a cartoon style shooter on Battlefield line of games. Video available here

What You Get At Google, And What You Don’t

“I’m thankful for the opportunity I had to work at Google. I learned more than I thought I would.

I’ll miss the free food.
I’ll miss the occasional massage.
I’ll miss the authors, politicians, and celebrities that come to speak or perform.
I’ll miss early chances to play with cool toys before they’re released to the public.
Most of all, I’ll miss working with the incredibly smart and talented people I got to know there.

But I won’t miss a design philosophy that lives or dies strictly by the sword of data.”
-Douglas Bowman, on his moving from Google to Twitter, March 2009

Noddy is no more

Image
Welcome, I believe you too are an animal lover and there’s pet(s) in your life, that’s much more…an animal companion. Well these guys have average life one-seventh or so of us, and thus we may see many pets, many generations in our Lifetime- can’t help it.

It still comforts if your pet dies a natural death in old age. Guess I am two time unlucky- My pet died. Died too early, at about four-and-half or five years of age.

Is your Google AdSense Showing clicks but no money? Checklist for solutions and suggested reading

Image
"not earning money but people click on ads""adsense showing click but not money""what's the deal with these zero value clicks?"

In Praise Of Moser Baer, and Some Thoughts On Movie Piracy in India

Image
Most of us watch movies, and we may buy DVDs/CDs for our personal collection also. In this case Moser Baer (India) is a company that keeps on pulling up surprises. I am impressed by the ingenuity of this company.

No Free Lunches- Credit That Image, or Shoot Yourself

Image
Dear Reader, I am a passionate photographer and believe in sharing knowledge. Thus, I have most of my photos (minus family ones) under Creative Commons Attribution license and I actively contribute to Wikipedia.

As most of the people who take out time to edit and enhance the mighty Wikipedia and release their photos, even outstanding ones for free- there is a reason for it.