SlideShare a Scribd company logo
E. Balagurusamy C PROGRAMMING: CHAPTER-4
Managing Input & output Operators
4.6 STATES ERRORS,IF ANY,IN THE FOLLOWING
STATEMENTS.
[A] :scanf(“%c %f %d”,city,&price,&year);
=NO ERROR.
[B] :scanf(“%s %d”,city,amount);
= THERE WILL BE A & BEFORE AMOUNT.
[C] :scanf(“%f %d”,&amount,&year);
=NO ERROR.
[D] :scanf(n”%f”,root);
=n will remain into double quote.
[E] :scanf(“%c %d %ld”,*code,&count,root);
=* IS NOT ALLOWED BEFORE CODE AND &WILL STAY
BEFORE ROOT.
4.7 WHAT WILL BE THE VALUES STORED OF THE VARIABLES
YEAR AND CODE WHEN THE DATA 1988,X ?
[A] :scanf(“%d %c”,&year,&code);
=YEAR STORS 1988 AND CODE STORS X.
[B] :scanf(“%c %d”,&year,&code);
= YEAR STORS X AND CODE STORS 1988.
[C] :scnaf(“%d %c”,&code,&year);
=CODE STORS 1988 AND YEAR STORS X.
4.8 COUNT,PRICE,CITY HAVE VALUES:
COUNT=1275,
PRICE=235.74,
CITY=CAMBRIDGE.
WHAT WILL BE THE OUTPUT THE STATEMENT ?
[A] :printf(“%d %f”,count,price);
OUTPUT=1275 235.75.
[B] :printf(“%d %f”,price,count);
OUTPUT=36576 790980
[C] :printf(“%c”,city);
OUTPUT=CAMBRIDGE
4.9 SHOW THE WRONG OF THE OUTPUT STATEMENTS.
[A] :printf(“%d.7.2%f”,year,amount);
WRONG=7.2 SHOULD REMAIN AFTER THE %
[B] :printf(“%-s,%c”n,city,code);
WRONG=COMMA IS NOT ALLOWED AND n SHOULD STAY
INTO QUOTATION.
[C] :printf(“%f %d %s”,price,count,city);
=NO WRONG.
4.10 WHAT VALUES DOSE THE COMPUTER ASSIGN OF THIS
INPUT STATEMENTS?
Scanf(“%4d %*d”,&year,&code,&count);
IF DATA KYED IN 19883745
0UTPUT=1988.
4.11 HOW CAN WE USE getcher() FUNCTION TO
MULTICHARACTER STRINGS?
= BY INCLUDING SINGLE QUOTATION OVER
MULTICHARACTER WE
CAN USE getchar() FUNCTION.
4.12 HOW CAN WE USE putchar() FUNCTION TO
MULTICHARACTER STRINGS?
= BY INCLUDING SINGLE QUOTATION OVER
MULTICHARACTER WE
CAN USE putchar() FUNCTION.
4.13 WHAT IS THE PURPOSE OF scanf() FUNCTION?
=IF WE WANT TO TAKE DATA AFTAR RUNNING THE
PROGRAMM THEN
WE USE scanf FUNCTION.
4.14 DESCRIBE THE PURPOSE OF COMMONLY USED
CONVERSION CHARACTERS IN A scanf() FUNCTION ?
=IT INDICATES WHAT TYPES OF DATA WE TAKE AS INPUT.
4.15 WHAT HAPPENS WHEN AN INPUT DATA ITEM CONTAIN ?
[A] MORE CHARACTERS THAN SPECIFIED FIELD WIDTH.
=VALUE WILL BE RIGHT-JUSTIFIED.
[B] FEWER CHARACTER THAN SPECIFIED FIELD WIDTH.
=VALUE WILL BE LEFT-JUSTEFIED.
4.16 WHAT IS THE PURPOSE OF printf() FUNCTION ?
=IT IS USED TO SHOW ANYTHIG ON OUTPUT.
4.17 DESCRIBE THE PURPOSE OF COMMONLY USED
CONVERSION CHARACTERS IN A printf() FUNCTION ?
= IT INDICATES WHAT TYPES OF DATA WE WANT TO SHOW
ON
OUTPUT.
4.18 WHAT HAPPENS WHEN AN 0UTPUT DATA ITEM
CONTAIN ?
[A] MORE CHARACTERS THAN SPECIFIED FIELD WIDTH.
=VALUE WILL BE RIGHT-JUSTIFIED.
[B] FEWER CHARACTER THAN SPECIFIED FIELD WIDTH.
=VALUE WILL BE LEFT-JUSTEFIED.
Problem no. 4.1:Given the string“WORDPROCESSING”,
Write a program to read the string from the terminal and
Display the same in the following format:
(a)WORD PROCESSING
(b)WORD
PROCESSING
(c) W.P.
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
char s[10],d[11];
clrscr();
printf("Enter the string: ");
scanf("%4s%10s",s,d);
printf("(a)%s %sn",s,d);
printf("(b)%sn%sn",s,d);
printf("(c)%.1s.%.1s",s,d);
getch();
}
Output:
Enter the string: WORDPROCESSING
(a) WORDPROCESSING
(b) WORD
PROCESSING
(c) W.P.
Problem no. 4.2: Write a program to read the values of x and y and print
the results of the following expression in one line:
(a)(x+y)/(x-y) (b)(x+y)/2 (c)(x+y)*(x-y)
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
float x,y,a,b,c;
clrscr();
printf("Enter the value of x & y: ");
scanf("%f%f",&x,&y);
if(x-y==0)
printf("(a)=imagine");
else
{
a=(x+y)/(x-y);
printf("(a)=%.2f",a);
}
b=(x+y)/2;
c=(x+y)*(x-y);
printf(" (b)=%.2f (c)=%.2f",b,c);
getch();
}
Output:
Enter the value of x & y: 4 3
(a)=7.00
(b)=3.50
(c)=12.00
Enter the value of x & y: 7 7
(a)= imagine
(b)=7.00
(c)=0.00
Problem no. 4.3: Write a program to read the following numbers, round
them off to the nearest integers and print out
the results in integer form:
35.7 50.21 -23.73 -46.45
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int p,i;
float a;
clrscr();
printf("ENTER REAL NUMBER FOR GET NEAREST INTEGER
NUMBERn");
for(i=1;i<=4;i++)
{
scanf("%f",&a);
if(a>=0)
p=a+0.5;
else
p=a-0.5;
printf("nNEAREST INTEGER NUMBER OF %f IS=
%dn",a,(int)p);
}
getch();
}
Output:
ENTER REAL NUMBER FOR GET NEAREST INTEGER
NUMBER 35.7
NEAREST INTEGER NUMBER OF 35.7 IS= 36
ENTER REAL NUMBER FOR GET NEAREST INTEGER
NUMBER 50.21
NEAREST INTEGER NUMBER OF 50.21 IS=50
ENTER REAL NUMBER FOR GET NEAREST INTEGER
NUMBER -23.73
NEAREST INTEGER NUMBER OF -23.73 IS= -24
ENTER REAL NUMBER FOR GET NEAREST INTEGER
NUMBER -46.45
NEAREST INTEGER NUMBER OF -46.45 IS= -46
Problem no. 4.4:write a program that read 4 floating values in the range,
0.0 to20.0, and prints a horizontal bar chart to represent these values
using the character * as the fill character. For the purpose of the chart,
the values may be rounded off to the nearest integer . For the example ,
the value 4.36 should be represented as follos,
* * * *
* * * * 4.36
* * * *
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
float a1,a2,a3,a4;
int x,y,z,t,i;
clrscr();
printf("Enter four float number:");
scanf("%f%f%f%f",&a1,&a2,&a3,&a4);
x=a1+0.5;y=a2+0.5;z=a3+0.5;t=a4+0.5;
printf("The horizontal bar chard is:n");
for(i=0;i<x;i++)
printf("* ");
printf("%.2fn",a1);
for(i=0;i<y;i++)
printf("* ");
printf("%.2fn",a2);
for(i=0;i<z;i++)
printf("* ");
printf("%.2fn",a3);
for(i=0;i<t;i++)
printf("* ");
printf("%.2fn",a4);
getch();
}
Output:
Enter four float number: 4.85 4.36 3.12 5.47
The horizontal bar chard is:
* * * * * 4.85
* * * * 4.36
* * * 3.12
* * * * * 5.47
Problem no.4.5: Write a program to demonstrate the process of
multiplication. The program should ask the user to enter two two digit
integer and print the product of integers as shown bellow.
45
X 37
7x45 is 315
3x45is 135
Add them 1665
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,p;
clrscr();
printf("Enter 2 two digits number:");
scanf("%d%d",&a,&b);
printf(" t%4dntx%3dn",a,b);
printf("t------n");
p=b/10;
c=b%10;
printf("%dx%dis%6dn",c,a,c*a);
printf("%dx%dis%5dn",p,a,p*a);
printf("t-------n");
printf("Add them %dn",a*b);
printf("t-------");
getch();
}
Output:
45
X 37
7x45 is 315
3x45is 135
Add them 1665
Problem no.4.6: Write a program to read three integers from the
keyboard using one scanf statement and output them on one line
using:
(a)three printf statements,
(b)only one printf with conversion specifiers and
(c) only one printf without conversion specifiers.
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
clrscr();
printf("Enter three integer value of x,y,&z:");
scanf("%d%d%d",&x,&y,&z);
printf("(a) X=%d,",x);
printf("Y=%d,",y);
printf("Z=%dn",z);
printf("(b) X=%3d, Y=%2d, Z=%2dn",x,y,z);
printf("(c) X= %d, Y=%d, Z=
%d",x,y,z);
getch();
}
Output:
Enter three integer value of x,y,&z: 45 27 89
(a) X=45, Y=27, Z=89
(b) X=45, Y=27, Z=89
(c) X=45, Y=27, Z=89
Problem no.4.7: Write a program that prints the value 10.45678 in
exponential format with the following specifications:
(a)correct to two decimal place,
(b)correct to four decimal place and
(c)correct to eight decimal place.
Solution:
#include <stdio.h>
#include<conio.h>
int main(void)
{
float a=10.45678,x,y,z;
clrscr();
printf("%8.2en%10.4en%10.8e",a,a,a);
getch();
return 0;
}
Output:
1.04e+01
1.0456e+01
1.04567804e+01
Problem no.4.98 Write a program to print the value 345.6789 in fixed-
point format with the following specifications:
(a)correct to two decimal place,
(b)correct to four decimal place and
(c)correct to zero decimal place.
Solution:
#include <stdio.h>
#include<conio.h>
void main()
{
float a=345.6789;
clrscr();
printf("The two decimal place is: %.2fn",a);
printf("The five decimal place is: %.5fn",a);
printf("The zero decimal place is: %.0f",a);
getch();
}
Output:
The two decimal place is: 345.67
The five decimal place is: 345.67889
The two decimal place is: 345
Problem no.4.9: Write a program to read the name ANIL KUMAR
GUPTA in three parts using the scanf statement and to display the
same in the following format using the printf statement.
(a) ANIL K. GUPTA
(b) A. K. GUPTA
(c) GUPTA A. K.
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
char s[6],d[6],c[6];
clrscr();
printf("Enter the string:");
scanf("%5s%5s%5s",s,d,c);
printf("(a) %s %.1s. %sn",s,d,c);
printf("(b) %.1s.%.1s.%sn",s,d,c);
printf("(c) %.1s.%.1s.n",c,s,d);
getch();
}
Output:
Enter the string: ANIL KUMAR GUPTA
(a) ANIL K. GUPTA
( b) A. K. GUPTA
(d) GUPTA A. K.
Problem no.4.10: Write a program to read and disply the following table
of data
Name Code Price
Fan 67831 1234.50
Motor 450 5786.70
The name and code must be left-justified and price must be
right-justified .
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int code1,code2;
float price1,price2;
char name1[10],name2[10];
clrscr();
printf("Enter first name ,code and price :");
scanf("%s%d%f",name1,&code1,&price1);
printf("Enter second name ,code and price :");
scanf("%s%d%f",name2,&code2,&price2);
printf("NametCodetPricen");
printf("%-st%-dt%.2fn",name1,code1,price1);
printf("%-st%-dt%.2fn",name2,code2,price2);
getch();
}
Output:
Enter first name ,code and price : Fan 67831 1234.50
Enter second name ,code and price : Motor 450 5786.70
Name Code Price
Fan 67831 1234.50
Motor 450 5786.70
Reference:
http://hstuadmission.blogspot.com/2010/12/solution-programming-in-
ansi-c-chapter.html

More Related Content

What's hot

The solution manual of programming in ansi by Robin
The solution manual of programming in ansi by RobinThe solution manual of programming in ansi by Robin
The solution manual of programming in ansi by Robin
Shariful Haque Robin
 
Let us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solutionLet us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solution
rohit kumar
 
Let us c chapter 4 solution
Let us c chapter 4 solutionLet us c chapter 4 solution
Let us c chapter 4 solution
rohit kumar
 
Let us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solutionLet us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solution
Hazrat Bilal
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
Sreedhar Chowdam
 
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionLet us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Hazrat Bilal
 
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
rohit kumar
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robin
Abdullah Al Naser
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
KavyaSharma65
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
Wingston
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
Rahul Pandit
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
Muthuganesh S
 
PPS Arrays Matrix operations
PPS Arrays Matrix operationsPPS Arrays Matrix operations
PPS Arrays Matrix operations
Sreedhar Chowdam
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
Sazzad Hossain, ITP, MBA, CSCA™
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
Aniket Patne
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
RAJ KUMAR
 
11 constructors in derived classes
11 constructors in derived classes11 constructors in derived classes
11 constructors in derived classes
Docent Education
 
LET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERSLET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERS
KavyaSharma65
 

What's hot (20)

The solution manual of programming in ansi by Robin
The solution manual of programming in ansi by RobinThe solution manual of programming in ansi by Robin
The solution manual of programming in ansi by Robin
 
Let us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solutionLet us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solution
 
Let us c chapter 4 solution
Let us c chapter 4 solutionLet us c chapter 4 solution
Let us c chapter 4 solution
 
Let us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solutionLet us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solution
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
 
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionLet us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
 
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robin
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Function in c
Function in cFunction in c
Function in c
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
 
PPS Arrays Matrix operations
PPS Arrays Matrix operationsPPS Arrays Matrix operations
PPS Arrays Matrix operations
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
11 constructors in derived classes
11 constructors in derived classes11 constructors in derived classes
11 constructors in derived classes
 
LET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERSLET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERS
 

Similar to Chapter 4 : Balagurusamy Programming ANSI in C

Najmul
Najmul  Najmul
Najmul
Najmul Ashik
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
JAYA
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
Md Masudur Rahman
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C Lab
Neil Mathew
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
Zaibi Gondal
 
C file
C fileC file
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
yogini sharma
 
C important questions
C important questionsC important questions
C important questions
JYOTI RANJAN PAL
 
C-programs
C-programsC-programs
C-programs
SSGMCE SHEGAON
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysisVishal Singh
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
Kuntal Bhowmick
 
C lab
C labC lab
C Language Programming Introduction Lecture
C Language Programming Introduction LectureC Language Programming Introduction Lecture
C Language Programming Introduction Lecture
myinstalab
 
C Programming
C ProgrammingC Programming
C Programming
Raj vardhan
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docx
tristans3
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
PRATHAMESH DESHPANDE
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
MKalpanaDevi
 

Similar to Chapter 4 : Balagurusamy Programming ANSI in C (20)

Najmul
Najmul  Najmul
Najmul
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C Lab
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
C file
C fileC file
C file
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
C important questions
C important questionsC important questions
C important questions
 
C-programs
C-programsC-programs
C-programs
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
C
CC
C
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
C lab
C labC lab
C lab
 
C Language Programming Introduction Lecture
C Language Programming Introduction LectureC Language Programming Introduction Lecture
C Language Programming Introduction Lecture
 
C Programming
C ProgrammingC Programming
C Programming
 
Basic Input and Output
Basic Input and OutputBasic Input and Output
Basic Input and Output
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docx
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 

More from BUBT

Lab report cover page
Lab report cover page Lab report cover page
Lab report cover page
BUBT
 
Project report title cover page
Project report title cover pageProject report title cover page
Project report title cover page
BUBT
 
Implementation Of GSM Based Fire Alarm and Protection System
Implementation Of GSM Based Fire Alarm and Protection SystemImplementation Of GSM Based Fire Alarm and Protection System
Implementation Of GSM Based Fire Alarm and Protection System
BUBT
 
Student Attendance
Student AttendanceStudent Attendance
Student Attendance
BUBT
 
Reasoning for Artificial Intelligence Expert
Reasoning for Artificial Intelligence ExpertReasoning for Artificial Intelligence Expert
Reasoning for Artificial Intelligence Expert
BUBT
 
Auto Room Lighting and Door lock Report
Auto Room Lighting and Door lock ReportAuto Room Lighting and Door lock Report
Auto Room Lighting and Door lock Report
BUBT
 
Auto Room Lighting System
Auto Room Lighting SystemAuto Room Lighting System
Auto Room Lighting System
BUBT
 
Doorlock
DoorlockDoorlock
Doorlock
BUBT
 
Ultra Dense Netwok
Ultra Dense NetwokUltra Dense Netwok
Ultra Dense Netwok
BUBT
 
Bangladesh University of Business and Technology
Bangladesh University of Business and Technology Bangladesh University of Business and Technology
Bangladesh University of Business and Technology
BUBT
 
Art Gallery Management System
Art Gallery Management SystemArt Gallery Management System
Art Gallery Management System
BUBT
 
Shop management system
Shop management systemShop management system
Shop management system
BUBT
 

More from BUBT (12)

Lab report cover page
Lab report cover page Lab report cover page
Lab report cover page
 
Project report title cover page
Project report title cover pageProject report title cover page
Project report title cover page
 
Implementation Of GSM Based Fire Alarm and Protection System
Implementation Of GSM Based Fire Alarm and Protection SystemImplementation Of GSM Based Fire Alarm and Protection System
Implementation Of GSM Based Fire Alarm and Protection System
 
Student Attendance
Student AttendanceStudent Attendance
Student Attendance
 
Reasoning for Artificial Intelligence Expert
Reasoning for Artificial Intelligence ExpertReasoning for Artificial Intelligence Expert
Reasoning for Artificial Intelligence Expert
 
Auto Room Lighting and Door lock Report
Auto Room Lighting and Door lock ReportAuto Room Lighting and Door lock Report
Auto Room Lighting and Door lock Report
 
Auto Room Lighting System
Auto Room Lighting SystemAuto Room Lighting System
Auto Room Lighting System
 
Doorlock
DoorlockDoorlock
Doorlock
 
Ultra Dense Netwok
Ultra Dense NetwokUltra Dense Netwok
Ultra Dense Netwok
 
Bangladesh University of Business and Technology
Bangladesh University of Business and Technology Bangladesh University of Business and Technology
Bangladesh University of Business and Technology
 
Art Gallery Management System
Art Gallery Management SystemArt Gallery Management System
Art Gallery Management System
 
Shop management system
Shop management systemShop management system
Shop management system
 

Recently uploaded

PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 

Recently uploaded (20)

PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 

Chapter 4 : Balagurusamy Programming ANSI in C

  • 1. E. Balagurusamy C PROGRAMMING: CHAPTER-4 Managing Input & output Operators 4.6 STATES ERRORS,IF ANY,IN THE FOLLOWING STATEMENTS. [A] :scanf(“%c %f %d”,city,&price,&year); =NO ERROR. [B] :scanf(“%s %d”,city,amount); = THERE WILL BE A & BEFORE AMOUNT. [C] :scanf(“%f %d”,&amount,&year); =NO ERROR. [D] :scanf(n”%f”,root); =n will remain into double quote. [E] :scanf(“%c %d %ld”,*code,&count,root); =* IS NOT ALLOWED BEFORE CODE AND &WILL STAY BEFORE ROOT. 4.7 WHAT WILL BE THE VALUES STORED OF THE VARIABLES YEAR AND CODE WHEN THE DATA 1988,X ? [A] :scanf(“%d %c”,&year,&code); =YEAR STORS 1988 AND CODE STORS X. [B] :scanf(“%c %d”,&year,&code); = YEAR STORS X AND CODE STORS 1988. [C] :scnaf(“%d %c”,&code,&year);
  • 2. =CODE STORS 1988 AND YEAR STORS X. 4.8 COUNT,PRICE,CITY HAVE VALUES: COUNT=1275, PRICE=235.74, CITY=CAMBRIDGE. WHAT WILL BE THE OUTPUT THE STATEMENT ? [A] :printf(“%d %f”,count,price); OUTPUT=1275 235.75. [B] :printf(“%d %f”,price,count); OUTPUT=36576 790980 [C] :printf(“%c”,city); OUTPUT=CAMBRIDGE 4.9 SHOW THE WRONG OF THE OUTPUT STATEMENTS. [A] :printf(“%d.7.2%f”,year,amount); WRONG=7.2 SHOULD REMAIN AFTER THE % [B] :printf(“%-s,%c”n,city,code); WRONG=COMMA IS NOT ALLOWED AND n SHOULD STAY INTO QUOTATION. [C] :printf(“%f %d %s”,price,count,city); =NO WRONG. 4.10 WHAT VALUES DOSE THE COMPUTER ASSIGN OF THIS INPUT STATEMENTS? Scanf(“%4d %*d”,&year,&code,&count); IF DATA KYED IN 19883745
  • 3. 0UTPUT=1988. 4.11 HOW CAN WE USE getcher() FUNCTION TO MULTICHARACTER STRINGS? = BY INCLUDING SINGLE QUOTATION OVER MULTICHARACTER WE CAN USE getchar() FUNCTION. 4.12 HOW CAN WE USE putchar() FUNCTION TO MULTICHARACTER STRINGS? = BY INCLUDING SINGLE QUOTATION OVER MULTICHARACTER WE CAN USE putchar() FUNCTION. 4.13 WHAT IS THE PURPOSE OF scanf() FUNCTION? =IF WE WANT TO TAKE DATA AFTAR RUNNING THE PROGRAMM THEN WE USE scanf FUNCTION. 4.14 DESCRIBE THE PURPOSE OF COMMONLY USED CONVERSION CHARACTERS IN A scanf() FUNCTION ? =IT INDICATES WHAT TYPES OF DATA WE TAKE AS INPUT. 4.15 WHAT HAPPENS WHEN AN INPUT DATA ITEM CONTAIN ? [A] MORE CHARACTERS THAN SPECIFIED FIELD WIDTH. =VALUE WILL BE RIGHT-JUSTIFIED. [B] FEWER CHARACTER THAN SPECIFIED FIELD WIDTH. =VALUE WILL BE LEFT-JUSTEFIED. 4.16 WHAT IS THE PURPOSE OF printf() FUNCTION ? =IT IS USED TO SHOW ANYTHIG ON OUTPUT.
  • 4. 4.17 DESCRIBE THE PURPOSE OF COMMONLY USED CONVERSION CHARACTERS IN A printf() FUNCTION ? = IT INDICATES WHAT TYPES OF DATA WE WANT TO SHOW ON OUTPUT. 4.18 WHAT HAPPENS WHEN AN 0UTPUT DATA ITEM CONTAIN ? [A] MORE CHARACTERS THAN SPECIFIED FIELD WIDTH. =VALUE WILL BE RIGHT-JUSTIFIED. [B] FEWER CHARACTER THAN SPECIFIED FIELD WIDTH. =VALUE WILL BE LEFT-JUSTEFIED. Problem no. 4.1:Given the string“WORDPROCESSING”, Write a program to read the string from the terminal and Display the same in the following format: (a)WORD PROCESSING (b)WORD PROCESSING (c) W.P. Solution: #include<stdio.h> #include<conio.h>
  • 5. void main() { char s[10],d[11]; clrscr(); printf("Enter the string: "); scanf("%4s%10s",s,d); printf("(a)%s %sn",s,d); printf("(b)%sn%sn",s,d); printf("(c)%.1s.%.1s",s,d); getch(); } Output: Enter the string: WORDPROCESSING (a) WORDPROCESSING (b) WORD PROCESSING (c) W.P. Problem no. 4.2: Write a program to read the values of x and y and print the results of the following expression in one line: (a)(x+y)/(x-y) (b)(x+y)/2 (c)(x+y)*(x-y)
  • 6. Solution: #include<stdio.h> #include<conio.h> void main() { float x,y,a,b,c; clrscr(); printf("Enter the value of x & y: "); scanf("%f%f",&x,&y); if(x-y==0) printf("(a)=imagine"); else { a=(x+y)/(x-y); printf("(a)=%.2f",a); } b=(x+y)/2; c=(x+y)*(x-y); printf(" (b)=%.2f (c)=%.2f",b,c); getch(); }
  • 7. Output: Enter the value of x & y: 4 3 (a)=7.00 (b)=3.50 (c)=12.00 Enter the value of x & y: 7 7 (a)= imagine (b)=7.00 (c)=0.00 Problem no. 4.3: Write a program to read the following numbers, round them off to the nearest integers and print out the results in integer form: 35.7 50.21 -23.73 -46.45 Solution: #include<stdio.h> #include<conio.h> void main() { int p,i; float a;
  • 8. clrscr(); printf("ENTER REAL NUMBER FOR GET NEAREST INTEGER NUMBERn"); for(i=1;i<=4;i++) { scanf("%f",&a); if(a>=0) p=a+0.5; else p=a-0.5; printf("nNEAREST INTEGER NUMBER OF %f IS= %dn",a,(int)p); } getch(); } Output: ENTER REAL NUMBER FOR GET NEAREST INTEGER NUMBER 35.7 NEAREST INTEGER NUMBER OF 35.7 IS= 36 ENTER REAL NUMBER FOR GET NEAREST INTEGER NUMBER 50.21 NEAREST INTEGER NUMBER OF 50.21 IS=50 ENTER REAL NUMBER FOR GET NEAREST INTEGER NUMBER -23.73
  • 9. NEAREST INTEGER NUMBER OF -23.73 IS= -24 ENTER REAL NUMBER FOR GET NEAREST INTEGER NUMBER -46.45 NEAREST INTEGER NUMBER OF -46.45 IS= -46 Problem no. 4.4:write a program that read 4 floating values in the range, 0.0 to20.0, and prints a horizontal bar chart to represent these values using the character * as the fill character. For the purpose of the chart, the values may be rounded off to the nearest integer . For the example , the value 4.36 should be represented as follos, * * * * * * * * 4.36 * * * * Solution: #include<stdio.h> #include<conio.h> void main() { float a1,a2,a3,a4; int x,y,z,t,i;
  • 10. clrscr(); printf("Enter four float number:"); scanf("%f%f%f%f",&a1,&a2,&a3,&a4); x=a1+0.5;y=a2+0.5;z=a3+0.5;t=a4+0.5; printf("The horizontal bar chard is:n"); for(i=0;i<x;i++) printf("* "); printf("%.2fn",a1); for(i=0;i<y;i++) printf("* "); printf("%.2fn",a2); for(i=0;i<z;i++) printf("* "); printf("%.2fn",a3); for(i=0;i<t;i++) printf("* "); printf("%.2fn",a4); getch(); } Output: Enter four float number: 4.85 4.36 3.12 5.47 The horizontal bar chard is:
  • 11. * * * * * 4.85 * * * * 4.36 * * * 3.12 * * * * * 5.47 Problem no.4.5: Write a program to demonstrate the process of multiplication. The program should ask the user to enter two two digit integer and print the product of integers as shown bellow. 45 X 37 7x45 is 315 3x45is 135 Add them 1665 Solution: #include<stdio.h> #include<conio.h> void main() { int a,b,c,p; clrscr(); printf("Enter 2 two digits number:"); scanf("%d%d",&a,&b); printf(" t%4dntx%3dn",a,b);
  • 12. printf("t------n"); p=b/10; c=b%10; printf("%dx%dis%6dn",c,a,c*a); printf("%dx%dis%5dn",p,a,p*a); printf("t-------n"); printf("Add them %dn",a*b); printf("t-------"); getch(); } Output: 45 X 37 7x45 is 315 3x45is 135 Add them 1665 Problem no.4.6: Write a program to read three integers from the keyboard using one scanf statement and output them on one line using: (a)three printf statements, (b)only one printf with conversion specifiers and (c) only one printf without conversion specifiers.
  • 13. Solution: #include<stdio.h> #include<conio.h> void main() { int x,y,z; clrscr(); printf("Enter three integer value of x,y,&z:"); scanf("%d%d%d",&x,&y,&z); printf("(a) X=%d,",x); printf("Y=%d,",y); printf("Z=%dn",z); printf("(b) X=%3d, Y=%2d, Z=%2dn",x,y,z); printf("(c) X= %d, Y=%d, Z= %d",x,y,z); getch(); } Output: Enter three integer value of x,y,&z: 45 27 89 (a) X=45, Y=27, Z=89 (b) X=45, Y=27, Z=89 (c) X=45, Y=27, Z=89
  • 14. Problem no.4.7: Write a program that prints the value 10.45678 in exponential format with the following specifications: (a)correct to two decimal place, (b)correct to four decimal place and (c)correct to eight decimal place. Solution: #include <stdio.h> #include<conio.h> int main(void) { float a=10.45678,x,y,z; clrscr();
  • 15. printf("%8.2en%10.4en%10.8e",a,a,a); getch(); return 0; } Output: 1.04e+01 1.0456e+01 1.04567804e+01 Problem no.4.98 Write a program to print the value 345.6789 in fixed- point format with the following specifications: (a)correct to two decimal place,
  • 16. (b)correct to four decimal place and (c)correct to zero decimal place. Solution: #include <stdio.h> #include<conio.h> void main() { float a=345.6789; clrscr(); printf("The two decimal place is: %.2fn",a); printf("The five decimal place is: %.5fn",a); printf("The zero decimal place is: %.0f",a); getch(); } Output: The two decimal place is: 345.67 The five decimal place is: 345.67889 The two decimal place is: 345
  • 17. Problem no.4.9: Write a program to read the name ANIL KUMAR GUPTA in three parts using the scanf statement and to display the same in the following format using the printf statement. (a) ANIL K. GUPTA (b) A. K. GUPTA (c) GUPTA A. K. Solution: #include<stdio.h> #include<conio.h> void main()
  • 18. { char s[6],d[6],c[6]; clrscr(); printf("Enter the string:"); scanf("%5s%5s%5s",s,d,c); printf("(a) %s %.1s. %sn",s,d,c); printf("(b) %.1s.%.1s.%sn",s,d,c); printf("(c) %.1s.%.1s.n",c,s,d); getch(); } Output: Enter the string: ANIL KUMAR GUPTA (a) ANIL K. GUPTA ( b) A. K. GUPTA (d) GUPTA A. K.
  • 19. Problem no.4.10: Write a program to read and disply the following table of data Name Code Price Fan 67831 1234.50 Motor 450 5786.70 The name and code must be left-justified and price must be right-justified . Solution: #include<stdio.h> #include<conio.h> void main() { int code1,code2; float price1,price2; char name1[10],name2[10]; clrscr(); printf("Enter first name ,code and price :"); scanf("%s%d%f",name1,&code1,&price1); printf("Enter second name ,code and price :"); scanf("%s%d%f",name2,&code2,&price2); printf("NametCodetPricen"); printf("%-st%-dt%.2fn",name1,code1,price1);
  • 20. printf("%-st%-dt%.2fn",name2,code2,price2); getch(); } Output: Enter first name ,code and price : Fan 67831 1234.50 Enter second name ,code and price : Motor 450 5786.70 Name Code Price Fan 67831 1234.50 Motor 450 5786.70 Reference: http://hstuadmission.blogspot.com/2010/12/solution-programming-in- ansi-c-chapter.html