Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Solutions to C Programming Balagurusamy, Study Guides, Projects, Research of C programming

It contains solution for the back exercise questions.

Typology: Study Guides, Projects, Research

2019/2020

Uploaded on 01/19/2020

smit-patel-3
smit-patel-3 🇮🇳

1 document

1 / 227

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CHAPTER 1
1.1 Write a program that will print your mailing address in the following form :
First line : Name
Second line : Door No, Street
Third line : City, Pin code
Algorithm: -
Algorithm to print your mailing address.
Step 1 : Display your Name and Go to new line.
Step 2 : Display your Door No and Street and Go to new line.
Step 3 : Display your City and Pin Code.
Flowchart:-
Program: -
// Write a program that will print your mailing
//address in the following form:
//First line : Name
//Second line : Door No, Strret
//Third line : City, Pin Code
//Date : 11/03/2013
START
Display your Name
& Go to new line
Display your Door
No and Street & go
to new line
Display your City
and Pin Code
END
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Solutions to C Programming Balagurusamy and more Study Guides, Projects, Research C programming in PDF only on Docsity!

CHAPTER 1

1.1 Write a program that will print your mailing address in the following form :

First line : Name Second line : Door No, Street Third line : City, Pin code

Algorithm: -

Algorithm to print your mailing address.

Step 1 : Display your Name and Go to new line. Step 2 : Display your Door No and Street and Go to new line. Step 3 : Display your City and Pin Code.

Flowchart:-

Program: -

// Write a program that will print your mailing //address in the following form: //First line : Name //Second line : Door No, Strret //Third line : City, Pin Code //Date : 11/03/201 3

START

Display your Name & Go to new line Display your Door No and Street & go to new line Display your City and Pin Code

END

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

void main() { clrscr(); printf("Name :-- HEMANT TRIVEDI\n"); printf("Door No :-- 103 , Street :-- Aradhna \n"); printf("City :-- Bhavnagar , Pin Code :-- 364001 "); getch(); }

Output:--

Name :-- HEMANT TRIVEDI | Door No:-- 103 Street:- Aradhna City:-- Bhavnagar, Pin Code:-- 364001

1.2 Modify the above program to provide border lines to the address.

Algorithm: -

Algorithm to provide border lines to address.

Step 1 : Display ------------------------------------------------- line and Go to new line. Step 2 : Display ------------------------------------------------- line and Go to new line. Step 3 : Display ||, your Name, || and Go to new line. Step 4 : Display ||, your Door No and Street, || and Go to new line. Step 5 : Display ||, your City, Pin Code, || and Go to new line. Step 6 : Display ------------------------------------------------- line and Go to new line. Step 7 : Display ------------------------------------------------- line.

Flowchart :-

START

Display ------------ & go to new line Display ------------ & go to new line

A

printf(" -----------------------------------------------\n"); printf(" -----------------------------------------------\n"); printf("|| Name :-- HEMANT TRIVEDI ||\n"); printf("|| Door No :-- 103 , Street :-- Aradhana ||\n"); printf("|| City :-- Bhavnagar , Pin Code :-- 364001 ||\n"); printf(" -----------------------------------------------\n"); printf(" -----------------------------------------------\n"); getch(); }

Output:-



|| Name :-- HEMANT TRIVEDI || || Door No:-- 103 , Street:- Aradhana || ||City:-- Bhavnagar, Pin Code:-- 364001 ||



1.3 Write a program using one print statement to print the pattern of asterisks as shown below :




Algorithm: -

Algorithm to print the pattern of pattern of asterisks.

Step 1: Display * and go to new line Step 2: Display * * and go to new line. Step 3: Display * * * and go to new line. Step 4: Display * * * * Flowchart:-

Program :-

START

Display * & Go to new line Display * * & go to new line Display * * * & go to new line Display * * * *

END

//Write a program using one print statement to //print the pattern of asterisks as shown below :

//* //* * //* * * //* * * *

#include<stdio.h> #include<conio.h> void main() { clrscr(); printf("* \n* * \n* * * \n* * * *"); getch(); }

Output: -




1.4 Write a program that will print the following figure using suitable charactes.


| | | | | | >>------------------- | |


Algorithm:--

Algorithm to print the figure using suitable characters.

Step 1: Display ---------- and spaces Step 2: Display ---------- and Go to new line Step 3: Display | | and spaces Step 4: Display | | and go to new line Step 5: Display | | Step 6: Display >>----------- Step 7: Display | | and go to new line Step 8: Display ---------- and spaces Step 9: Display ----------

printf("-------------"); printf(" ") printf("-------------"); getch(); }

Output :--


| | | | | | >>-------------------> | |


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

Algorithm:--

Algorithm to compute the area of circle.

Step 1: Store 3.14 to varable PIE. Step 2: Store 4 to variable Rad. Step 3: Compute the area of circle and assign it to variable Area. Area = PIE * Rad * Rad Step 4: Display the variable.

Flowchart:--

Program :--

//Given the radius of a circle, write a program to compute

START

PIE = 3.

Rad = 4

Area=PIERadRad

Display Area

END

//and display its area. Use a symbolic constant to define the //PIE value and assume a suitable value for radius.

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

#Define PIE 3.

void main() { clrscr();

float Rad,Area; Rad=4; Area=PIERadRad; printf("Area of a circle is--> %f",Area); getch(); }

Output:--

Area of a circle is 50.

1.6 Write a program to output the following multiplication table.

5 * 1 = 5 * 2 = 5 * 3 =

.. .. .. 5 * 10 =

Algorithm:--

Algorithm to print multiplication table.

Step 1: Display 5 * 1 = 5 and go to new line Step 2: Display 5 * 2 = 10 and go to new line Step 3: Display 5 * 3 = 15 and go to new line Step 4: Display 5 * 4 = 20 and go to new line Step 5: Display 5 * 5 = 25 and go to new line Step 6: Display 5 * 6 = 30 and go to new line Step 7: Display 5 * 7 = 35 and go to new line Step 8: Display 5 * 8 = 40 and go to new line Step 9: Display 5 * 9 = 45 and go to new line Step 10: Display 5 * 10 = 50 and go to new line

Flowchart:--

Output:--

1.7 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

Algorithm:--

Step 1: Display First Number 20. Step 2: Display Second Number 10. Step 3: Call function add(20,10) to add these two numbers and store result in variable Sum. Step 4: Call function sub(20,10) to Subtract these two numbers and store result in variable Diff. Step 5: Display 20 + 10 = Step 6: Display Sum and go to new line. Step 7: Display 20 – 10 = Step 6: Display Diff.

Flowchart:--

Program:--

//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

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

void main() { clrscr();

int Sum,Diff; printf("First Number 20\n"); printf("Second Number 10\n");

Sum=20+10; Diff=20-10;

printf("20 + 10 = %d\n", Sum);

Display First Number 20 Display Second Number 10

Sum=20+ Diff=20-

Display 20 + 10 = and Sum & go to new line Display 20 - 10 = and Diff

START

END

Program:--

//Given the values of three variables a, b and c, //write a program to compute and display the values of x, where

//X= a / (b - c)

//Execute your program for the following values:

//(a) a=250, b==85,c= //(b) a=300, b=70, c=

//Comment on the output in each case.

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

void main() { clrscr();

int a,b,c; float x; a=250; b=85; c=25; x=a/(b-c);

printf("x = %f\n",x);

A

a= b= c=

x= a / (b – c)

Display X

START

T

a=300; b=70; c=70; x=a/(b-c);

printf("x = %f\n",x);

getch(); }

Output:--

x=4. Divide error

1.9 Relationship between Celsius and Fahrenheit is governed by the formula

F = (9C/5)+ Write a program to convert the temperature (a) from Celsius to Fahrenheit and (b) from Fahrenheit to Celsius.

Algorithm:--

Algorithm to convert from Celsius to Fahrenheit and from Fahrenheit to Celsius.

Step 1: Store 0 to F & C. Step 2: Store 200 to C. Step 3: Compute ((9c)/5)+32 and store the result in F. Step 4: Display F. Step 5: Store 300 to F. Step 6: Compute ((F-32)5)/9 and store the result in C. Step 7: Display C.

float F,C; clrscr();

C=200; F=(((9*C)/5)+32);

printf("Celsius = %f to Fahrenheit = %f\n",C,F);

F=300; C=((F-32)*5)/9;

printf("Fahrenheit = %f to Celsius = %f\n",F,C);

getch(); }

Output:--

Celsius =200.000000 to Fahrenheit = 392. Fahrenheit = 300.000000 to Celsius = 148.

1.10 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.

Algorithm:--

Algorithm to compute the area of a triangle.

Step 1: Store 0 to a, b ,c and S. Step 2: Store 20, 30 and 40 to a, b and c respectively. Step 3: Compute (a+b+c)/2 and store the result in S. Step 4: Compute sqrt(S(S-a)(S-b)*(S-c)) and store the result in Area. Step 5: Display Area.

Flowchart:--

Program:--

//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.

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

void main() {

int a,b,c; float S,Area; a=b=c=S=0;

clrscr();

a=20;

START

a= b= c= S=

a= b= c=

S= (a+b+c)/c

Area=sqrt(S(S-a)(S-b)*(S-c))

END

//Distance between two points (x1,y1) and (x2,y2) is governed by the formula

//D2 = (x2-x1)2+(y2-y1)

//Write a program to compute D given the coordinates of the points.

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

void main() {

int x1,x2,y1,y2; float D; D=0; x1=20; x2=30; y1=40; y2=50;

clrscr();

D=sqrt((x2-x1)(x2-x1)+ (y2-y1) (y2-y1));

printf("Distance between to points is= %f",D);

getch(); }

Output:--

Distance between twoo points is = 14.

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

Algorithm:--

Algorithm to compute perimeter and area of the circle.

Step 1: Store the coordinate of origin O1 and O2 to 0, 0 respectively. Step 2: Store the coordinate of point x1 and y1 to 4, 5 respectively. Step 3: Compute sqrt((x1-O1)(x1-O1)+ (y1-O2) (y1-O2)) and store the result in Rad. Step 4: Compute 2PIERad and store the result in Circum. Step 5: Compute PIERadRad and store the result in Area. Step 6: Display Circum & Area.

Flowchart:--

Program:--

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

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

#define PIE 3.

void main() {

int O1,O2,x1,y2; float Rad,Circum,Area;

clrscr();

Rad=sqrt((x1-O1)(x1-O1)+ (y1-O2) (y1-O2))); Circum=2PIERad; Area=PIERadRad;

printf("Circumference is= %f \n Area is= %f",Circum,Area);

getch(); }

O1=

O2=

x1= x2=

Rad= sqrt((x1-O1)(x1-O1)+ (y1-O2) (y1-O2)) Circum=2PIERad Area= PIERadRad

Display Circum Display Area

START

START