SlideShare a Scribd company logo
1 of 9
Download to read offline
/**
C program that prompts user to enter two floating point
type values and print the product of two values upt to 3
decimal places
*/
//program1.c
//header files
#include
#include
//main function
int main()
{
//declare two double type variables
double num1;
double num2;
//set a double variable,product=0
double product=0;
printf("Enter num1 and num2: ");
//prompt for num1 and num2 values from keyboard
scanf("%lf %lf",&num1,&num2);
//calculate product
product=num1*num2;
//print product of two numbers and limit product to 3 decimal places
printf("The product of %lf and %lf is %5.3lf  ",num1,num2,product);
getch();
return 0;
}
Sample output:
Enter num1 and num2: 2.25 3.25
The product of 2.250000 and 3.250000 is 7.313
------------------------------------------------------------------------------------
//2.
/**
C program that prompts user to enter integer values
until user enters 999 to stop reading. Then prit
number of even and odd to console.
*/
//program2.c
//header files
#include
#include
//main function
int main()
{
//set SENTINAL=999;
int SENTINAL=999;
//declare integer variable
int value;
//set even and odd=0
int even=0;
int odd=0;
printf("Enter a vlaue or 999 to stop reading input ");
scanf("%d",&value);
//read until value is not 999
while(value!=SENTINAL)
{
//check if value is even
if(value%2==0)
//increment even by one
even++;
else
//otherwise increment odd by one
odd++;
printf("Enter a vlaue or 999 to stop reading input ");
//read a value
scanf("%d",&value);
}
printf("Even numbers : %d ",even);
printf("Odd numbers : %d ",odd);
//pause program output on console
getch();
return 0;
}
Sample output:
Enter a vlaue or 999 to stop reading input 1
Enter a vlaue or 999 to stop reading input 2
Enter a vlaue or 999 to stop reading input 3
Enter a vlaue or 999 to stop reading input 4
Enter a vlaue or 999 to stop reading input 5
Enter a vlaue or 999 to stop reading input 6
Enter a vlaue or 999 to stop reading input 7
Enter a vlaue or 999 to stop reading input 8
Enter a vlaue or 999 to stop reading input 9
Enter a vlaue or 999 to stop reading input 10
Enter a vlaue or 999 to stop reading input 999
Even numbers : 5
Odd numbers : 5
------------------------------------------------------------------------------------------------------------
//3.
/**
C program that prompts length in inches and prints the length
in miles, yards, feet to console.
*/
//program3.c
//header files
#include
#include
//function prototype
void measure(int inch,int &m,int &y,int &f, int &i);
//main function
int main()
{
int miles,yards,feet,inches=0;
int len;
printf("Enter the length (inches): ");
//prompt for len
scanf("%d",&len);
//calling measure method
measure(len,miles,yards,feet,inches);
//print len
printf("Total length : %d ", len);
//print miles,yards, feet and inches
printf("Miles : %d ", miles);
printf("Yards : %d ", yards);
printf("Feet : %d ", feet);
printf("Inches : %d ", inches);
//pause program output on console
getch();
return 0;
}
/**
The method measure that takes inches and four address (reference) of variables
m,y,f and i and calcualtes the miles, yards,feet and inches.
*/
void measure(int inch,int &m,int &y,int &f, int &i)
{
int total;
total = inch;
m = total/ 63360;
total = total%63360;
y = total /36;
total = total%36;
f = total/12;
total = total%12;
i = total;
}
sample outout:
Enter the length (inches): 835
Total length : 835
Miles : 0
Yards : 23
Feet : 0
Inches : 7
Solution
/**
C program that prompts user to enter two floating point
type values and print the product of two values upt to 3
decimal places
*/
//program1.c
//header files
#include
#include
//main function
int main()
{
//declare two double type variables
double num1;
double num2;
//set a double variable,product=0
double product=0;
printf("Enter num1 and num2: ");
//prompt for num1 and num2 values from keyboard
scanf("%lf %lf",&num1,&num2);
//calculate product
product=num1*num2;
//print product of two numbers and limit product to 3 decimal places
printf("The product of %lf and %lf is %5.3lf  ",num1,num2,product);
getch();
return 0;
}
Sample output:
Enter num1 and num2: 2.25 3.25
The product of 2.250000 and 3.250000 is 7.313
------------------------------------------------------------------------------------
//2.
/**
C program that prompts user to enter integer values
until user enters 999 to stop reading. Then prit
number of even and odd to console.
*/
//program2.c
//header files
#include
#include
//main function
int main()
{
//set SENTINAL=999;
int SENTINAL=999;
//declare integer variable
int value;
//set even and odd=0
int even=0;
int odd=0;
printf("Enter a vlaue or 999 to stop reading input ");
scanf("%d",&value);
//read until value is not 999
while(value!=SENTINAL)
{
//check if value is even
if(value%2==0)
//increment even by one
even++;
else
//otherwise increment odd by one
odd++;
printf("Enter a vlaue or 999 to stop reading input ");
//read a value
scanf("%d",&value);
}
printf("Even numbers : %d ",even);
printf("Odd numbers : %d ",odd);
//pause program output on console
getch();
return 0;
}
Sample output:
Enter a vlaue or 999 to stop reading input 1
Enter a vlaue or 999 to stop reading input 2
Enter a vlaue or 999 to stop reading input 3
Enter a vlaue or 999 to stop reading input 4
Enter a vlaue or 999 to stop reading input 5
Enter a vlaue or 999 to stop reading input 6
Enter a vlaue or 999 to stop reading input 7
Enter a vlaue or 999 to stop reading input 8
Enter a vlaue or 999 to stop reading input 9
Enter a vlaue or 999 to stop reading input 10
Enter a vlaue or 999 to stop reading input 999
Even numbers : 5
Odd numbers : 5
------------------------------------------------------------------------------------------------------------
//3.
/**
C program that prompts length in inches and prints the length
in miles, yards, feet to console.
*/
//program3.c
//header files
#include
#include
//function prototype
void measure(int inch,int &m,int &y,int &f, int &i);
//main function
int main()
{
int miles,yards,feet,inches=0;
int len;
printf("Enter the length (inches): ");
//prompt for len
scanf("%d",&len);
//calling measure method
measure(len,miles,yards,feet,inches);
//print len
printf("Total length : %d ", len);
//print miles,yards, feet and inches
printf("Miles : %d ", miles);
printf("Yards : %d ", yards);
printf("Feet : %d ", feet);
printf("Inches : %d ", inches);
//pause program output on console
getch();
return 0;
}
/**
The method measure that takes inches and four address (reference) of variables
m,y,f and i and calcualtes the miles, yards,feet and inches.
*/
void measure(int inch,int &m,int &y,int &f, int &i)
{
int total;
total = inch;
m = total/ 63360;
total = total%63360;
y = total /36;
total = total%36;
f = total/12;
total = total%12;
i = total;
}
sample outout:
Enter the length (inches): 835
Total length : 835
Miles : 0
Yards : 23
Feet : 0
Inches : 7

More Related Content

Similar to C program that prompts user to enter two floating point t.pdf

Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdfTask #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdfinfo706022
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++Marco Izzotti
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALPrabhu D
 
Lab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docxLab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docxDIPESH30
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notesRajiv Gupta
 
Verilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSVerilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSDr.YNM
 
Unit3 overview of_c_programming
Unit3 overview of_c_programmingUnit3 overview of_c_programming
Unit3 overview of_c_programmingCapuchino HuiNing
 
CC++ echo serverThis assignment is designed to introduce network .pdf
CC++ echo serverThis assignment is designed to introduce network .pdfCC++ echo serverThis assignment is designed to introduce network .pdf
CC++ echo serverThis assignment is designed to introduce network .pdfsecunderbadtirumalgi
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 solIIUM
 
Lesson 2 starting output
Lesson 2 starting outputLesson 2 starting output
Lesson 2 starting outputWayneJones104
 
ECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docx
ECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docxECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docx
ECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docxjack60216
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfabdulrahamanbags
 
Write a program that reads in integer as many as the user enters from.docx
Write a program that reads in integer as many as the user enters from.docxWrite a program that reads in integer as many as the user enters from.docx
Write a program that reads in integer as many as the user enters from.docxlez31palka
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 

Similar to C program that prompts user to enter two floating point t.pdf (20)

Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdfTask #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
User Defined Functions in C Language
User Defined Functions   in  C LanguageUser Defined Functions   in  C Language
User Defined Functions in C Language
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
 
Lab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docxLab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docx
 
BScPLSQL.pdf
BScPLSQL.pdfBScPLSQL.pdf
BScPLSQL.pdf
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notes
 
Verilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSVerilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONS
 
Unit3 overview of_c_programming
Unit3 overview of_c_programmingUnit3 overview of_c_programming
Unit3 overview of_c_programming
 
CC++ echo serverThis assignment is designed to introduce network .pdf
CC++ echo serverThis assignment is designed to introduce network .pdfCC++ echo serverThis assignment is designed to introduce network .pdf
CC++ echo serverThis assignment is designed to introduce network .pdf
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 sol
 
Lesson 2 starting output
Lesson 2 starting outputLesson 2 starting output
Lesson 2 starting output
 
ECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docx
ECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docxECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docx
ECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docx
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
 
Spl book salution
Spl book salutionSpl book salution
Spl book salution
 
Write a program that reads in integer as many as the user enters from.docx
Write a program that reads in integer as many as the user enters from.docxWrite a program that reads in integer as many as the user enters from.docx
Write a program that reads in integer as many as the user enters from.docx
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 

More from aoneonlinestore1

1. VacuolesThe vacuole is an organelle in plant cells which stores.pdf
1. VacuolesThe vacuole is an organelle in plant cells which stores.pdf1. VacuolesThe vacuole is an organelle in plant cells which stores.pdf
1. VacuolesThe vacuole is an organelle in plant cells which stores.pdfaoneonlinestore1
 
1. B) - Two independent properties serve to specify the state.2. B.pdf
1. B) - Two independent properties serve to specify the state.2. B.pdf1. B) - Two independent properties serve to specify the state.2. B.pdf
1. B) - Two independent properties serve to specify the state.2. B.pdfaoneonlinestore1
 
(NH4)2SO4 is a soluble salt and is fully ionized in solution(NH4).pdf
(NH4)2SO4 is a soluble salt and is fully ionized in solution(NH4).pdf(NH4)2SO4 is a soluble salt and is fully ionized in solution(NH4).pdf
(NH4)2SO4 is a soluble salt and is fully ionized in solution(NH4).pdfaoneonlinestore1
 
I have inserted spaces. Consider f(x) belonging to f(X) thi.pdf
 I have inserted spaces. Consider f(x) belonging to f(X) thi.pdf I have inserted spaces. Consider f(x) belonging to f(X) thi.pdf
I have inserted spaces. Consider f(x) belonging to f(X) thi.pdfaoneonlinestore1
 
The carbonyl functional group in glucose is an al.pdf
                     The carbonyl functional group in glucose is an al.pdf                     The carbonyl functional group in glucose is an al.pdf
The carbonyl functional group in glucose is an al.pdfaoneonlinestore1
 
Well to find the pH at the equivalance point. Acc.pdf
                     Well to find the pH at the equivalance point. Acc.pdf                     Well to find the pH at the equivalance point. Acc.pdf
Well to find the pH at the equivalance point. Acc.pdfaoneonlinestore1
 
The weakest base in the reaction is A the enolat.pdf
                     The weakest base in the reaction is A the enolat.pdf                     The weakest base in the reaction is A the enolat.pdf
The weakest base in the reaction is A the enolat.pdfaoneonlinestore1
 
so take an aliquot of the upper layer and add a f.pdf
                     so take an aliquot of the upper layer and add a f.pdf                     so take an aliquot of the upper layer and add a f.pdf
so take an aliquot of the upper layer and add a f.pdfaoneonlinestore1
 
moles of NH4Cl formed = 20.050 = 0.1 moles so we.pdf
                     moles of NH4Cl formed = 20.050 = 0.1 moles so we.pdf                     moles of NH4Cl formed = 20.050 = 0.1 moles so we.pdf
moles of NH4Cl formed = 20.050 = 0.1 moles so we.pdfaoneonlinestore1
 
Latency is a measure of time delay experienced in.pdf
                     Latency is a measure of time delay experienced in.pdf                     Latency is a measure of time delay experienced in.pdf
Latency is a measure of time delay experienced in.pdfaoneonlinestore1
 
Entropy is the measure of disorder. Therefore, th.pdf
                     Entropy is the measure of disorder. Therefore, th.pdf                     Entropy is the measure of disorder. Therefore, th.pdf
Entropy is the measure of disorder. Therefore, th.pdfaoneonlinestore1
 
dydx = 1x dy = dxx y = ln x + c .pdf
                     dydx = 1x dy = dxx y = ln x + c               .pdf                     dydx = 1x dy = dxx y = ln x + c               .pdf
dydx = 1x dy = dxx y = ln x + c .pdfaoneonlinestore1
 
Ø Napoleonic era brought some relief to the faltering ottoman empire.pdf
Ø Napoleonic era brought some relief to the faltering ottoman empire.pdfØ Napoleonic era brought some relief to the faltering ottoman empire.pdf
Ø Napoleonic era brought some relief to the faltering ottoman empire.pdfaoneonlinestore1
 
YES=Cathode rays have mass. .yes=Matter contains positive and nega.pdf
YES=Cathode rays have mass. .yes=Matter contains positive and nega.pdfYES=Cathode rays have mass. .yes=Matter contains positive and nega.pdf
YES=Cathode rays have mass. .yes=Matter contains positive and nega.pdfaoneonlinestore1
 
TWEEN ENGINE1.Tween engine is universal.2.Reusability of tween .pdf
TWEEN ENGINE1.Tween engine is universal.2.Reusability of tween .pdfTWEEN ENGINE1.Tween engine is universal.2.Reusability of tween .pdf
TWEEN ENGINE1.Tween engine is universal.2.Reusability of tween .pdfaoneonlinestore1
 
To identify the identity of Variable Interest Entity , first of all .pdf
To identify the identity of Variable Interest Entity , first of all .pdfTo identify the identity of Variable Interest Entity , first of all .pdf
To identify the identity of Variable Interest Entity , first of all .pdfaoneonlinestore1
 
technology is the application of scientific knowledge. technology is.pdf
technology is the application of scientific knowledge. technology is.pdftechnology is the application of scientific knowledge. technology is.pdf
technology is the application of scientific knowledge. technology is.pdfaoneonlinestore1
 
b)The cations on the left side act as oxidants. C.pdf
                     b)The cations on the left side act as oxidants. C.pdf                     b)The cations on the left side act as oxidants. C.pdf
b)The cations on the left side act as oxidants. C.pdfaoneonlinestore1
 
Plants have shown gradual and greater evolutionary trends. The plant.pdf
Plants have shown gradual and greater evolutionary trends. The plant.pdfPlants have shown gradual and greater evolutionary trends. The plant.pdf
Plants have shown gradual and greater evolutionary trends. The plant.pdfaoneonlinestore1
 

More from aoneonlinestore1 (20)

1. VacuolesThe vacuole is an organelle in plant cells which stores.pdf
1. VacuolesThe vacuole is an organelle in plant cells which stores.pdf1. VacuolesThe vacuole is an organelle in plant cells which stores.pdf
1. VacuolesThe vacuole is an organelle in plant cells which stores.pdf
 
1. B) - Two independent properties serve to specify the state.2. B.pdf
1. B) - Two independent properties serve to specify the state.2. B.pdf1. B) - Two independent properties serve to specify the state.2. B.pdf
1. B) - Two independent properties serve to specify the state.2. B.pdf
 
(NH4)2SO4 is a soluble salt and is fully ionized in solution(NH4).pdf
(NH4)2SO4 is a soluble salt and is fully ionized in solution(NH4).pdf(NH4)2SO4 is a soluble salt and is fully ionized in solution(NH4).pdf
(NH4)2SO4 is a soluble salt and is fully ionized in solution(NH4).pdf
 
I have inserted spaces. Consider f(x) belonging to f(X) thi.pdf
 I have inserted spaces. Consider f(x) belonging to f(X) thi.pdf I have inserted spaces. Consider f(x) belonging to f(X) thi.pdf
I have inserted spaces. Consider f(x) belonging to f(X) thi.pdf
 
The carbonyl functional group in glucose is an al.pdf
                     The carbonyl functional group in glucose is an al.pdf                     The carbonyl functional group in glucose is an al.pdf
The carbonyl functional group in glucose is an al.pdf
 
Well to find the pH at the equivalance point. Acc.pdf
                     Well to find the pH at the equivalance point. Acc.pdf                     Well to find the pH at the equivalance point. Acc.pdf
Well to find the pH at the equivalance point. Acc.pdf
 
The weakest base in the reaction is A the enolat.pdf
                     The weakest base in the reaction is A the enolat.pdf                     The weakest base in the reaction is A the enolat.pdf
The weakest base in the reaction is A the enolat.pdf
 
so take an aliquot of the upper layer and add a f.pdf
                     so take an aliquot of the upper layer and add a f.pdf                     so take an aliquot of the upper layer and add a f.pdf
so take an aliquot of the upper layer and add a f.pdf
 
moles of NH4Cl formed = 20.050 = 0.1 moles so we.pdf
                     moles of NH4Cl formed = 20.050 = 0.1 moles so we.pdf                     moles of NH4Cl formed = 20.050 = 0.1 moles so we.pdf
moles of NH4Cl formed = 20.050 = 0.1 moles so we.pdf
 
Latency is a measure of time delay experienced in.pdf
                     Latency is a measure of time delay experienced in.pdf                     Latency is a measure of time delay experienced in.pdf
Latency is a measure of time delay experienced in.pdf
 
Entropy is the measure of disorder. Therefore, th.pdf
                     Entropy is the measure of disorder. Therefore, th.pdf                     Entropy is the measure of disorder. Therefore, th.pdf
Entropy is the measure of disorder. Therefore, th.pdf
 
dydx = 1x dy = dxx y = ln x + c .pdf
                     dydx = 1x dy = dxx y = ln x + c               .pdf                     dydx = 1x dy = dxx y = ln x + c               .pdf
dydx = 1x dy = dxx y = ln x + c .pdf
 
Ø Napoleonic era brought some relief to the faltering ottoman empire.pdf
Ø Napoleonic era brought some relief to the faltering ottoman empire.pdfØ Napoleonic era brought some relief to the faltering ottoman empire.pdf
Ø Napoleonic era brought some relief to the faltering ottoman empire.pdf
 
YES=Cathode rays have mass. .yes=Matter contains positive and nega.pdf
YES=Cathode rays have mass. .yes=Matter contains positive and nega.pdfYES=Cathode rays have mass. .yes=Matter contains positive and nega.pdf
YES=Cathode rays have mass. .yes=Matter contains positive and nega.pdf
 
TWEEN ENGINE1.Tween engine is universal.2.Reusability of tween .pdf
TWEEN ENGINE1.Tween engine is universal.2.Reusability of tween .pdfTWEEN ENGINE1.Tween engine is universal.2.Reusability of tween .pdf
TWEEN ENGINE1.Tween engine is universal.2.Reusability of tween .pdf
 
upSolutionup.pdf
upSolutionup.pdfupSolutionup.pdf
upSolutionup.pdf
 
To identify the identity of Variable Interest Entity , first of all .pdf
To identify the identity of Variable Interest Entity , first of all .pdfTo identify the identity of Variable Interest Entity , first of all .pdf
To identify the identity of Variable Interest Entity , first of all .pdf
 
technology is the application of scientific knowledge. technology is.pdf
technology is the application of scientific knowledge. technology is.pdftechnology is the application of scientific knowledge. technology is.pdf
technology is the application of scientific knowledge. technology is.pdf
 
b)The cations on the left side act as oxidants. C.pdf
                     b)The cations on the left side act as oxidants. C.pdf                     b)The cations on the left side act as oxidants. C.pdf
b)The cations on the left side act as oxidants. C.pdf
 
Plants have shown gradual and greater evolutionary trends. The plant.pdf
Plants have shown gradual and greater evolutionary trends. The plant.pdfPlants have shown gradual and greater evolutionary trends. The plant.pdf
Plants have shown gradual and greater evolutionary trends. The plant.pdf
 

Recently uploaded

TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 

Recently uploaded (20)

TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 

C program that prompts user to enter two floating point t.pdf

  • 1. /** C program that prompts user to enter two floating point type values and print the product of two values upt to 3 decimal places */ //program1.c //header files #include #include //main function int main() { //declare two double type variables double num1; double num2; //set a double variable,product=0 double product=0; printf("Enter num1 and num2: "); //prompt for num1 and num2 values from keyboard scanf("%lf %lf",&num1,&num2); //calculate product product=num1*num2; //print product of two numbers and limit product to 3 decimal places printf("The product of %lf and %lf is %5.3lf ",num1,num2,product); getch(); return 0; } Sample output: Enter num1 and num2: 2.25 3.25 The product of 2.250000 and 3.250000 is 7.313 ------------------------------------------------------------------------------------ //2. /** C program that prompts user to enter integer values
  • 2. until user enters 999 to stop reading. Then prit number of even and odd to console. */ //program2.c //header files #include #include //main function int main() { //set SENTINAL=999; int SENTINAL=999; //declare integer variable int value; //set even and odd=0 int even=0; int odd=0; printf("Enter a vlaue or 999 to stop reading input "); scanf("%d",&value); //read until value is not 999 while(value!=SENTINAL) { //check if value is even if(value%2==0) //increment even by one even++; else //otherwise increment odd by one odd++; printf("Enter a vlaue or 999 to stop reading input "); //read a value scanf("%d",&value); } printf("Even numbers : %d ",even);
  • 3. printf("Odd numbers : %d ",odd); //pause program output on console getch(); return 0; } Sample output: Enter a vlaue or 999 to stop reading input 1 Enter a vlaue or 999 to stop reading input 2 Enter a vlaue or 999 to stop reading input 3 Enter a vlaue or 999 to stop reading input 4 Enter a vlaue or 999 to stop reading input 5 Enter a vlaue or 999 to stop reading input 6 Enter a vlaue or 999 to stop reading input 7 Enter a vlaue or 999 to stop reading input 8 Enter a vlaue or 999 to stop reading input 9 Enter a vlaue or 999 to stop reading input 10 Enter a vlaue or 999 to stop reading input 999 Even numbers : 5 Odd numbers : 5 ------------------------------------------------------------------------------------------------------------ //3. /** C program that prompts length in inches and prints the length in miles, yards, feet to console. */ //program3.c //header files #include #include //function prototype void measure(int inch,int &m,int &y,int &f, int &i); //main function int main() { int miles,yards,feet,inches=0;
  • 4. int len; printf("Enter the length (inches): "); //prompt for len scanf("%d",&len); //calling measure method measure(len,miles,yards,feet,inches); //print len printf("Total length : %d ", len); //print miles,yards, feet and inches printf("Miles : %d ", miles); printf("Yards : %d ", yards); printf("Feet : %d ", feet); printf("Inches : %d ", inches); //pause program output on console getch(); return 0; } /** The method measure that takes inches and four address (reference) of variables m,y,f and i and calcualtes the miles, yards,feet and inches. */ void measure(int inch,int &m,int &y,int &f, int &i) { int total; total = inch; m = total/ 63360; total = total%63360; y = total /36; total = total%36; f = total/12; total = total%12; i = total; } sample outout:
  • 5. Enter the length (inches): 835 Total length : 835 Miles : 0 Yards : 23 Feet : 0 Inches : 7 Solution /** C program that prompts user to enter two floating point type values and print the product of two values upt to 3 decimal places */ //program1.c //header files #include #include //main function int main() { //declare two double type variables double num1; double num2; //set a double variable,product=0 double product=0; printf("Enter num1 and num2: "); //prompt for num1 and num2 values from keyboard scanf("%lf %lf",&num1,&num2); //calculate product product=num1*num2; //print product of two numbers and limit product to 3 decimal places printf("The product of %lf and %lf is %5.3lf ",num1,num2,product); getch(); return 0;
  • 6. } Sample output: Enter num1 and num2: 2.25 3.25 The product of 2.250000 and 3.250000 is 7.313 ------------------------------------------------------------------------------------ //2. /** C program that prompts user to enter integer values until user enters 999 to stop reading. Then prit number of even and odd to console. */ //program2.c //header files #include #include //main function int main() { //set SENTINAL=999; int SENTINAL=999; //declare integer variable int value; //set even and odd=0 int even=0; int odd=0; printf("Enter a vlaue or 999 to stop reading input "); scanf("%d",&value); //read until value is not 999 while(value!=SENTINAL) { //check if value is even if(value%2==0) //increment even by one even++; else
  • 7. //otherwise increment odd by one odd++; printf("Enter a vlaue or 999 to stop reading input "); //read a value scanf("%d",&value); } printf("Even numbers : %d ",even); printf("Odd numbers : %d ",odd); //pause program output on console getch(); return 0; } Sample output: Enter a vlaue or 999 to stop reading input 1 Enter a vlaue or 999 to stop reading input 2 Enter a vlaue or 999 to stop reading input 3 Enter a vlaue or 999 to stop reading input 4 Enter a vlaue or 999 to stop reading input 5 Enter a vlaue or 999 to stop reading input 6 Enter a vlaue or 999 to stop reading input 7 Enter a vlaue or 999 to stop reading input 8 Enter a vlaue or 999 to stop reading input 9 Enter a vlaue or 999 to stop reading input 10 Enter a vlaue or 999 to stop reading input 999 Even numbers : 5 Odd numbers : 5 ------------------------------------------------------------------------------------------------------------ //3. /** C program that prompts length in inches and prints the length in miles, yards, feet to console. */ //program3.c //header files #include
  • 8. #include //function prototype void measure(int inch,int &m,int &y,int &f, int &i); //main function int main() { int miles,yards,feet,inches=0; int len; printf("Enter the length (inches): "); //prompt for len scanf("%d",&len); //calling measure method measure(len,miles,yards,feet,inches); //print len printf("Total length : %d ", len); //print miles,yards, feet and inches printf("Miles : %d ", miles); printf("Yards : %d ", yards); printf("Feet : %d ", feet); printf("Inches : %d ", inches); //pause program output on console getch(); return 0; } /** The method measure that takes inches and four address (reference) of variables m,y,f and i and calcualtes the miles, yards,feet and inches. */ void measure(int inch,int &m,int &y,int &f, int &i) { int total; total = inch; m = total/ 63360;
  • 9. total = total%63360; y = total /36; total = total%36; f = total/12; total = total%12; i = total; } sample outout: Enter the length (inches): 835 Total length : 835 Miles : 0 Yards : 23 Feet : 0 Inches : 7