SlideShare a Scribd company logo
1 of 76
Structured Programming Language
# include <math.h>
Mohammad Imam Hossain,
Lecturer, CSE, UIU
Advanced problems on Operators
Flow Chart
โ€ข This whole slide is based on the following flow chart:
# include <math.h>
The math.h header declares a set of functions
to compute common mathematical operations
and transformations.
Ref: MathDotH.pdf
โ€œ Computers are good
at following
instructions, but not at
reading your mind. โ€ -
Donald Knuth
Problem
โ€ข Input: x (double)
โ€ข Output: y (double)
๐‘ฆ = 5๐‘ฅ4 + 3๐‘ฅ2 + 7 tan ๐‘ฅ โˆ’ ๐‘’ ๐‘ฅ + ๐‘ฅ
Solution
๐‘ฆ = 5๐‘ฅ4 + 3๐‘ฅ2 + 7 tan ๐‘ฅ โˆ’ ๐‘’ ๐‘ฅ + ๐‘ฅ#include <stdio.h>
int main()
{
return 0;
}
Solution
๐‘ฆ = 5๐‘ฅ4 + 3๐‘ฅ2 + 7 tan ๐‘ฅ โˆ’ ๐‘’ ๐‘ฅ + ๐‘ฅ#include <stdio.h>
int main()
{
double x,y; ///variable declaration
return 0;
}
Solution
๐‘ฆ = 5๐‘ฅ4 + 3๐‘ฅ2 + 7 tan ๐‘ฅ โˆ’ ๐‘’ ๐‘ฅ + ๐‘ฅ#include <stdio.h>
int main()
{
double x,y; ///variable declaration
printf("Please enter the value of x: ");
scanf(" %lf",&x); ///taking input the value of x
return 0;
}
Solution
๐‘ฆ = 5๐‘ฅ4 + 3๐‘ฅ2 + 7 tan ๐‘ฅ โˆ’ ๐‘’ ๐‘ฅ + ๐‘ฅ#include <stdio.h>
#include <math.h>
int main()
{
double x,y; ///variable declaration
printf("Please enter the value of x: ");
scanf(" %lf",&x); ///taking input the value of x
y=5*pow(x,4)+3*x*x+sqrt(7)*tan(x)-exp(x)+ceil(fabs(x)); ///Processing
return 0;
}
Solution
๐‘ฆ = 5๐‘ฅ4 + 3๐‘ฅ2 + 7 tan ๐‘ฅ โˆ’ ๐‘’ ๐‘ฅ + ๐‘ฅ#include <stdio.h>
#include <math.h>
int main()
{
double x,y; ///variable declaration
printf("Please enter the value of x: ");
scanf(" %lf",&x); ///taking input the value of x
y=5*pow(x,4)+3*x*x+sqrt(7)*tan(x)-exp(x)+ceil(fabs(x)); ///Processing
printf("The resulting value is %lfn",y); ///printing output
return 0;
}
Practice
โ€ข Input: a (double),
b(double) ,
c(double)
โ€ข Output: x (double)
๐‘ฅ =
5๐‘Ž2
+ 6๐‘ + ๐‘
2๐‘Ž + ๐‘
Problem
โ€ข Input: p (integer, no of watts of a light),
t (double, no of hours it is turned on)
โ€ข Output: no of B.O.T units in kwh format.
Problem
โ€ข Input: p (integer, no of watts of a light),
t (double, no of hours it is turned on)
โ€ข Output: no of B.O.T units in kwh format.
units =
๐‘๐‘ก
1000
๐พ๐‘Š๐ป
Code Sample
#include <stdio.h>
int main()
{
return 0;
}
Code Sample
#include <stdio.h>
int main()
{
double p,t,result;
printf("Enter the power(in watts) & used time(in hours): ");
scanf("%lf %lf",&p,&t); ///taking input
return 0;
}
Code Sample
#include <stdio.h>
int main()
{
double p,t,result;
printf("Enter the power(in watts) & used time(in hours): ");
scanf("%lf %lf",&p,&t); ///taking input
result=p*t/1000; ///calculating no of units
return 0;
}
Code Sample
#include <stdio.h>
int main()
{
double p,t,result;
printf("Enter the power(in watts) & used time(in hours): ");
scanf("%lf %lf",&p,&t); ///taking input
result=p*t/1000; ///calculating no of units
printf("No of units: %.2lfn",result); ///output
return 0;
}
Problem
โ€ข Write a program that will initialize two integer types
of variables (a ,b) and interchange(swap) the values
between them and finally show the output.
โ€ข Input: a=10, b=20
โ€ข Output: a=20, b=10
Code Sample
#include <stdio.h>
int main()
{
return 0;
}
Code Sample
#include <stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b); ///taking inputs
return 0;
}
Code Sample
#include <stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b); ///taking inputs
int temp; /// to hold temporary value
temp=a; /// saving a into temp
return 0;
}
Code Sample
#include <stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b); ///taking inputs
int temp; /// to hold temporary value
temp=a; /// saving a into temp
a=b; ///now a has the new value of b
return 0;
}
Code Sample
#include <stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b); ///taking inputs
int temp; /// to hold temporary value
temp=a; /// saving a into temp
a=b; ///now a has the new value of b
b=temp; ///now b has the value of temp(old value of a)
return 0;
}
Code Sample
#include <stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b); ///taking inputs
int temp; /// to hold temporary value
temp=a; /// saving a into temp
a=b; ///now a has the new value of b
b=temp; ///now b has the value of temp(old value of a)
printf("a=%d and b=%dn",a,b); ///output
return 0;
}
Problem
โ€ข Input: temperature(double) in ยฐC format.
โ€ข Output: temperature(double) in ยฐF format.
Problem
โ€ข Input: temperature(double) in ยฐC format.
โ€ข Output: temperature(double) in ยฐF format.
๐ถ โˆ’ 0
100 โˆ’ 0
=
๐น โˆ’ 32
212 โˆ’ 32
Code Sample
#include <stdio.h>
int main()
{
return 0;
}
Code Sample
#include <stdio.h>
int main()
{
double c,f;
printf("Enter temperature in Celsius: ");
scanf("%lf",&c); ///taking input Celsius scale temperature
return 0;
}
Code Sample
#include <stdio.h>
int main()
{
double c,f;
printf("Enter temperature in Celsius: ");
scanf("%lf",&c); ///taking input Celsius scale temperature
f= 9*c/5+32; /// processing
return 0;
}
Code Sample
#include <stdio.h>
int main()
{
double c,f;
printf("Enter temperature in Celsius: ");
scanf("%lf",&c); ///taking input Celsius scale temperature
f= 9*c/5+32; /// processing
printf("%.2lf Celsius = %.2lf Fahrenheit",c,f); ///output
return 0;
}
Problem
โ€ข Input: r (double, radius),
h (double, height)
โ€ข Output: the volume of a sphere
Problem
โ€ข Input: r (double, radius),
h (double, height)
โ€ข Output: the volume of a sphere
๐œ‹๐‘Ÿ2โ„Ž
Code Sample
#include <stdio.h>
int main()
{
return 0;
}
Code Sample
#include <stdio.h>
int main()
{
double radius,height,volume;
printf("please enter the radius and height of a cylinder: ");
scanf("%lf %lf",&radius,&height); ///taking inputs
return 0;
}
Code Sample
#include <stdio.h>
#define PI 3.1416
int main()
{
double radius,height,volume;
printf("please enter the radius and height of a cylinder: ");
scanf("%lf %lf",&radius,&height); ///taking inputs
volume = PI*radius*radius*height; ///calculating volume
return 0;
}
Code Sample
#include <stdio.h>
#define PI 3.1416
int main()
{
double radius,height,volume;
printf("please enter the radius and height of a cylinder: ");
scanf("%lf %lf",&radius,&height); ///taking inputs
volume = PI*radius*radius*height; ///calculating volume
printf("The volume of cylinder is %.3lfn",volume); ///output
return 0;
}
Problem
โ€ข Input: 6 floating point numbers
(x1, y1),
(x2, y2),
(x3, y3)
โ€ข Output: area (double, area of a triangle)
(๐‘ฅ1, ๐‘ฆ1)
(๐‘ฅ2, ๐‘ฆ2) (๐‘ฅ3, ๐‘ฆ3)
Problem
โ€ข Input: 6 floating point numbers
(x1, y1),
(x2, y2),
(x3, y3)
โ€ข Output: area (double, area of a triangle)
(๐‘ฅ1, ๐‘ฆ1)
(๐‘ฅ2, ๐‘ฆ2) (๐‘ฅ3, ๐‘ฆ3)
๐‘Ž๐‘Ÿ๐‘’๐‘Ž =
1
2
๐‘ฅ1 โˆ’ ๐‘ฅ2 โˆ— ๐‘ฆ2 โˆ’ ๐‘ฆ3 โˆ’ ๐‘ฆ1 โˆ’ ๐‘ฆ2 โˆ— ๐‘ฅ2 โˆ’ ๐‘ฅ3
=
1
2
[๐‘ฅ1 โˆ— ๐‘ฆ2 โˆ’ ๐‘ฆ3 + ๐‘ฅ2 โˆ— ๐‘ฆ3 โˆ’ ๐‘ฆ1 + ๐‘ฅ3 โˆ— ๐‘ฆ1 โˆ’ ๐‘ฆ2 ]
Code Sample#include <stdio.h>
int main()
{
return 0;
}
Code Sample#include <stdio.h>
int main()
{
double x1,y1,x2,y2,x3,y3;
printf("Enter the 3 vertices of a triangle: ");
scanf("%lf %lf",&x1,&y1);
scanf("%lf %lf",&x2,&y2);
scanf("%lf %lf",&x3,&y3); ///taking input
return 0;
}
Code Sample#include <stdio.h>
#include <math.h> ///for function fabs
int main()
{
double x1,y1,x2,y2,x3,y3;
printf("Enter the 3 vertices of a triangle: ");
scanf("%lf %lf",&x1,&y1);
scanf("%lf %lf",&x2,&y2);
scanf("%lf %lf",&x3,&y3); ///taking input
double area;
area=0.5*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2));///calculating
return 0;
}
Code Sample#include <stdio.h>
#include <math.h> ///for function fabs
int main()
{
double x1,y1,x2,y2,x3,y3;
printf("Enter the 3 vertices of a triangle: ");
scanf("%lf %lf",&x1,&y1);
scanf("%lf %lf",&x2,&y2);
scanf("%lf %lf",&x3,&y3); ///taking input
double area;
area=0.5*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2));///calculating
printf("The area is %.3lf sq units.nโ€œ,fabs(area));///outputs
return 0;
}
Practice
โ€ข Input: a , b (base and height of a right angle triangle)
โ€ข Output: the value of the hypotenuse
Practice
โ€ข Input: a , b (base and height of a right angle triangle)
โ€ข Output: the value of the hypotenuse
โ„Ž๐‘ฆ๐‘ = ๐‘๐‘Ž๐‘ ๐‘’2 + โ„Ž๐‘’๐‘–๐‘”โ„Ž๐‘ก2
base
hypotenuse
height
Problem
โ€ข Input: t (integer, time in seconds)
โ€ข Output: ddd days hh hours mm minutes and ss seconds
โ€ข Sample I/O:
Input: 123456
Output: 001 days 10 hours 17 minutes and 36 seconds
โ€œ First, solve the
problem. Then,
write the code. โ€ -
John Johnson
Code Sample#include <stdio.h>
int main()
{
return 0;
}
Code Sample#include <stdio.h>
int main()
{
int input;
scanf("%d",&input); ///taking input
return 0;
}
Code Sample#include <stdio.h>
int main()
{
int input;
scanf("%d",&input); ///taking input
int day,hr,min,sec,rem_sec;
return 0;
}
Code Sample#include <stdio.h>
int main()
{
int input;
scanf("%d",&input); ///taking input
int day,hr,min,sec,rem_sec;
day=input/(24*60*60); ///calculating no of days
rem_sec=input%(24*60*60); ///the remaining seconds
return 0;
}
Code Sample#include <stdio.h>
int main()
{
int input;
scanf("%d",&input); ///taking input
int day,hr,min,sec,rem_sec;
day=input/(24*60*60); ///calculating no of days
rem_sec=input%(24*60*60); ///the remaining seconds
hr=rem_sec/(60*60); ///calculating no of hours
rem_sec=rem_sec%(60*60); ///remaining seconds
return 0;
}
Code Sample#include <stdio.h>
int main()
{
int input;
scanf("%d",&input); ///taking input
int day,hr,min,sec,rem_sec;
day=input/(24*60*60); ///calculating no of days
rem_sec=input%(24*60*60); ///the remaining seconds
hr=rem_sec/(60*60); ///calculating no of hours
rem_sec=rem_sec%(60*60); ///remaining seconds
min=rem_sec/60; ///calculating no of minutes
sec=rem_sec%60; ///final remaining seconds
return 0;
}
Code Sample#include <stdio.h>
int main()
{
int input;
scanf("%d",&input); ///taking input
int day,hr,min,sec,rem_sec;
day=input/(24*60*60); ///calculating no of days
rem_sec=input%(24*60*60); ///the remaining seconds
hr=rem_sec/(60*60); ///calculating no of hours
rem_sec=rem_sec%(60*60); ///remaining seconds
min=rem_sec/60; ///calculating no of minutes
sec=rem_sec%60; ///final remaining seconds
printf("%03d days %02d hours %02d minutes and %02d seconds",day,hr,min,sec); ///output
return 0;
}
Problem
โ€ข Input: an integer of exactly 4 digits (for example, 1234)
โ€ข Output: 1 thousands, 2 hundreds and 34
Code Sample#include <stdio.h>
int main()
{
return 0;
}
Code Sample#include <stdio.h>
int main()
{
int num;
scanf("%4d",&num); ///taking input
return 0;
}
Code Sample#include <stdio.h>
int main()
{
int num;
scanf("%4d",&num); ///taking input
int thous,hund,rem,temp; ///declaring variables
return 0;
}
Code Sample#include <stdio.h>
int main()
{
int num;
scanf("%4d",&num); ///taking input
int thous,hund,rem,temp; ///declaring variables
thous=num/1000; /// calculating thousands
temp=num%1000; /// remaining amounts
return 0;
}
Code Sample#include <stdio.h>
int main()
{
int num;
scanf("%4d",&num); ///taking input
int thous,hund,rem,temp; ///declaring variables
thous=num/1000; /// calculating thousands
temp=num%1000; /// remaining amounts
hund=temp/100; ///calculating hundreds
rem=temp%100; ///final remaining amounts
return 0;
}
Code Sample#include <stdio.h>
int main()
{
int num;
scanf("%4d",&num); ///taking input
int thous,hund,rem,temp; ///declaring variables
thous=num/1000; /// calculating thousands
temp=num%1000; /// remaining amounts
hund=temp/100; ///calculating hundreds
rem=temp%100; ///final remaining amounts
printf("%d thousands, %d hundreds and %dn",thous,hund,rem); ///output
return 0;
}
Practice
โ€ข Input: an integer of exactly 4 digits (let, 1234)
โ€ข Output: the sum of the digits (10)
Problem
โ€ข Input: a, b, c of the equation ๐‘Ž๐‘ฅ2 + ๐‘๐‘ฅ + ๐‘ = 0
โ€ข Output: the roots of this equation.
Problem
โ€ข Input: a, b, c of the equation ๐‘Ž๐‘ฅ2 + ๐‘๐‘ฅ + ๐‘ = 0
โ€ข Output: the roots of this equation.
๐‘ฅ1 =
โˆ’๐‘ + ๐‘2 โˆ’ 4๐‘Ž๐‘
2๐‘Ž
๐‘ฅ2 =
โˆ’๐‘ โˆ’ ๐‘2 โˆ’ 4๐‘Ž๐‘
2๐‘Ž
Code Sample
#include <stdio.h>
#include <math.h>
int main()
{
return 0;
}
Code Sample
#include <stdio.h>
#include <math.h>
int main()
{
int a,b,c; ///ax^2+bx+c=0, coefficient input
scanf("%d %d %d",&a,&b,&c);
return 0;
}
Code Sample
#include <stdio.h>
#include <math.h>
int main()
{
int a,b,c; ///ax^2+bx+c=0, coefficient input
scanf("%d %d %d",&a,&b,&c);
double x1,x2; ///roots calculation
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
return 0;
}
Code Sample
#include <stdio.h>
#include <math.h>
int main()
{
int a,b,c; ///ax^2+bx+c=0, coefficient input
scanf("%d %d %d",&a,&b,&c);
double x1,x2; ///roots calculation
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
printf("Solutions are %lf and %lfn",x1,x2); ///output
return 0;
}
Practice
โ€ข Input: a1, b1, c1 and a2, b2, c2
where,
๐‘Ž1 ๐‘ฅ + ๐‘1 ๐‘ฆ + ๐‘1 = 0
๐‘Ž2 ๐‘ฅ + ๐‘2 ๐‘ฆ + ๐‘2 = 0
โ€ข Output: the intersection point of that two straight
lines.
Practice
โ€ข Input: a1, b1, c1 and a2, b2, c2
where,
๐‘Ž1 ๐‘ฅ + ๐‘1 ๐‘ฆ + ๐‘1 = 0
๐‘Ž2 ๐‘ฅ + ๐‘2 ๐‘ฆ + ๐‘2 = 0
โ€ข Output: the intersection point of that two straight
lines.
๐‘ฅ =
๐‘1 ๐‘2 โˆ’ ๐‘2 ๐‘1
๐‘Ž1 ๐‘2 โˆ’ ๐‘Ž2 ๐‘1
๐‘ฆ =
๐‘1 ๐‘Ž2 โˆ’ ๐‘2 ๐‘Ž1
๐‘Ž1 ๐‘2 โˆ’ ๐‘Ž2 ๐‘1
Code Sample
Practice
โ€ข Input: two integers indicating the hours and minutes
of an analog clock
โ€ข Output: the angle between the two indicators.
Problem
โ€ข Input: 3 angles(double) of a triangle.
โ€ข Output: a character
โ€˜Yโ€™ (if valid triangle)
โ€˜Nโ€™ (if not a valid triangle)
A
B C
A+B+C = ๐œ‹
Code Sample
#include <stdio.h>
int main()
{
double A,B,C;
scanf("%lf %lf %lf",&A,&B,&C);
char result;
result=(A+B+C-180.0 < 0.00000001)?'Y':'N';
printf("%cn",result);
return 0;
}
Practice
โ€ข Input: 3 double numbers from the user
โ€ข Output: average (double) of that 3 numbers.
Sample I/O:
โ€ข Input: 10.0,20.0,30.0
โ€ข Output: 20.000000
Practice
โ€ข Input: Grade points(double) of 6 subjects and their
corresponding credit hours(double).
โ€ข Output: weighted GPA
๐บ๐‘ƒ๐ด =
ฯƒ๐‘–=1
๐‘›
๐ถ๐‘– โˆ— ๐บ๐‘–
ฯƒ๐‘–=1
๐‘›
๐ถ๐‘–
Course Credits, ๐‘ช๐’Š Grade Points, ๐‘ฎ๐’Š ๐‘ช๐’Š * ๐‘ฎ๐’Š
CSE 100 2.00 4.00 8.00
EEE 163 3.00 4.00 12.00
EEE 164 1.50 3.75 5.625
MATH 141 3.00 3.00 9.00
ME 160 1.50 3.50 5.250
ME 165 3.00 4.00 12.00
PHY 109 4.00 3.75 15.00
PHY 102 1.50 3.50 5.250
Total 19.50 72.125
GPA calculation
๐บ๐‘ƒ๐ด =
72.125
19.50
= 3.7
Practice
โ€ข Input: Total credits(double) of 4 semesters and their
corresponding GPA(double) earned.
โ€ข Output: Cumulative GPA
C๐บ๐‘ƒ๐ด =
ฯƒ๐‘–=1
๐‘›
๐‘‡๐ถ๐‘– โˆ— ๐บ๐‘ƒ๐ด๐‘–
ฯƒ๐‘–=1
๐‘›
๐‘‡๐ถ๐‘–
Semester Total Credits, ๐“๐‘ช๐’Š GPA earned, ๐‘ฎ๐‘ท๐‘จ๐’Š ๐‘ป๐‘ช๐’Š * ๐‘ฎ๐‘ท๐‘จ๐’Š
1 19.50 3.70 72.150
2 20.50 3.93 80.565
3 21.25 3.96 84.150
4 20.25 4.00 81.00
Total 81.50 317.865
CGPA calculation
๐ถ๐บ๐‘ƒ๐ด =
317.865
81.50
= 3.90

More Related Content

What's hot

Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFTimur Safin
ย 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointersMomenMostafa
ย 
Operating system labs
Operating system labsOperating system labs
Operating system labsbhaktisagar4
ย 
Struct examples
Struct examplesStruct examples
Struct examplesmondalakash2012
ย 
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 ANSWERSKavyaSharma65
ย 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shortingargusacademy
ย 
C program
C programC program
C programKomal Singh
ย 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 FocJAYA
ย 
Program flowchart
Program flowchartProgram flowchart
Program flowchartSowri Rajan
ย 
Daa practicals
Daa practicalsDaa practicals
Daa practicalsRekha Yadav
ย 
Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programsKandarp Tiwari
ย 
C Programming
C ProgrammingC Programming
C ProgrammingSumant Diwakar
ย 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
ย 

What's hot (20)

Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
ย 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
ย 
Operating system labs
Operating system labsOperating system labs
Operating system labs
ย 
C++ file
C++ fileC++ file
C++ file
ย 
Struct examples
Struct examplesStruct examples
Struct examples
ย 
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
ย 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
ย 
C program
C programC program
C program
ย 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
ย 
Code optimization
Code optimization Code optimization
Code optimization
ย 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
ย 
Daa practicals
Daa practicalsDaa practicals
Daa practicals
ย 
Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programs
ย 
C Programming
C ProgrammingC Programming
C Programming
ย 
ADA FILE
ADA FILEADA FILE
ADA FILE
ย 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
ย 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
ย 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
ย 
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
ย 
Ray Tracing with ZIO
Ray Tracing with ZIORay Tracing with ZIO
Ray Tracing with ZIO
ย 

Similar to SPL 6.1 | Advanced problems on Operators and Math.h function in C

Similar to SPL 6.1 | Advanced problems on Operators and Math.h function in C (20)

Muzzammilrashid
MuzzammilrashidMuzzammilrashid
Muzzammilrashid
ย 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
ย 
901131 examples
901131 examples901131 examples
901131 examples
ย 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
ย 
Session06 functions
Session06 functionsSession06 functions
Session06 functions
ย 
Tu1
Tu1Tu1
Tu1
ย 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
ย 
C programming
C programmingC programming
C programming
ย 
C file
C fileC file
C file
ย 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
ย 
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
ย 
C lab
C labC lab
C lab
ย 
Intro to c programming
Intro to c programmingIntro to c programming
Intro to c programming
ย 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Embedded C - Day 2
ย 
C programming Lab 1
C programming Lab 1C programming Lab 1
C programming Lab 1
ย 
Chapter 5
Chapter 5Chapter 5
Chapter 5
ย 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
ย 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
ย 
C lab programs
C lab programsC lab programs
C lab programs
ย 
C lab programs
C lab programsC lab programs
C lab programs
ย 

More from Mohammad Imam Hossain

DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6Mohammad Imam Hossain
ย 
DS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic ProgrammingDS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic ProgrammingMohammad Imam Hossain
ย 
DS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MSTDS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MSTMohammad Imam Hossain
ย 
DS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchDS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchMohammad Imam Hossain
ย 
DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3Mohammad Imam Hossain
ย 
DS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and ConquerDS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and ConquerMohammad Imam Hossain
ย 
DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2Mohammad Imam Hossain
ย 
DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1Mohammad Imam Hossain
ย 
DS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionDS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionMohammad Imam Hossain
ย 
DBMS 1 | Introduction to DBMS
DBMS 1 | Introduction to DBMSDBMS 1 | Introduction to DBMS
DBMS 1 | Introduction to DBMSMohammad Imam Hossain
ย 
DBMS 10 | Database Transactions
DBMS 10 | Database TransactionsDBMS 10 | Database Transactions
DBMS 10 | Database TransactionsMohammad Imam Hossain
ย 
DBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational SchemaDBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational SchemaMohammad Imam Hossain
ย 
DBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship ModelDBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship ModelMohammad Imam Hossain
ย 
DBMS 7 | Relational Query Language
DBMS 7 | Relational Query LanguageDBMS 7 | Relational Query Language
DBMS 7 | Relational Query LanguageMohammad Imam Hossain
ย 
DBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsDBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsMohammad Imam Hossain
ย 
DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaMohammad Imam Hossain
ย 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckMohammad Imam Hossain
ย 

More from Mohammad Imam Hossain (20)

DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6
ย 
DS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic ProgrammingDS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic Programming
ย 
DS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MSTDS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MST
ย 
DS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchDS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path Search
ย 
DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3
ย 
DS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and ConquerDS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and Conquer
ย 
DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2
ย 
DS & Algo 2 - Recursion
DS & Algo 2 - RecursionDS & Algo 2 - Recursion
DS & Algo 2 - Recursion
ย 
DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1
ย 
DS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionDS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL Introduction
ย 
DBMS 1 | Introduction to DBMS
DBMS 1 | Introduction to DBMSDBMS 1 | Introduction to DBMS
DBMS 1 | Introduction to DBMS
ย 
DBMS 10 | Database Transactions
DBMS 10 | Database TransactionsDBMS 10 | Database Transactions
DBMS 10 | Database Transactions
ย 
DBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational SchemaDBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational Schema
ย 
DBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship ModelDBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship Model
ย 
DBMS 7 | Relational Query Language
DBMS 7 | Relational Query LanguageDBMS 7 | Relational Query Language
DBMS 7 | Relational Query Language
ย 
DBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsDBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML Commands
ย 
DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR Schema
ย 
TOC 10 | Turing Machine
TOC 10 | Turing MachineTOC 10 | Turing Machine
TOC 10 | Turing Machine
ย 
TOC 9 | Pushdown Automata
TOC 9 | Pushdown AutomataTOC 9 | Pushdown Automata
TOC 9 | Pushdown Automata
ย 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity Check
ย 

Recently uploaded

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
ย 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
ย 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
ย 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
ย 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
ย 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
ย 
USPSยฎ Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPSยฎ Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPSยฎ Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPSยฎ Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
ย 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
ย 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
ย 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
ย 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
ย 
call girls in Kamla Market (DELHI) ๐Ÿ” >เผ’9953330565๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Kamla Market (DELHI) ๐Ÿ” >เผ’9953330565๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธcall girls in Kamla Market (DELHI) ๐Ÿ” >เผ’9953330565๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Kamla Market (DELHI) ๐Ÿ” >เผ’9953330565๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
ย 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
ย 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
ย 

Recently uploaded (20)

Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
ย 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
ย 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
ย 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
ย 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
ย 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
ย 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
ย 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
ย 
USPSยฎ Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPSยฎ Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPSยฎ Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPSยฎ Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
ย 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
ย 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
ย 
Model Call Girl in Tilak Nagar Delhi reach out to us at ๐Ÿ”9953056974๐Ÿ”
Model Call Girl in Tilak Nagar Delhi reach out to us at ๐Ÿ”9953056974๐Ÿ”Model Call Girl in Tilak Nagar Delhi reach out to us at ๐Ÿ”9953056974๐Ÿ”
Model Call Girl in Tilak Nagar Delhi reach out to us at ๐Ÿ”9953056974๐Ÿ”
ย 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
ย 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
ย 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
ย 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
ย 
call girls in Kamla Market (DELHI) ๐Ÿ” >เผ’9953330565๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Kamla Market (DELHI) ๐Ÿ” >เผ’9953330565๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธcall girls in Kamla Market (DELHI) ๐Ÿ” >เผ’9953330565๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Kamla Market (DELHI) ๐Ÿ” >เผ’9953330565๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
ย 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
ย 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
ย 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ย 

SPL 6.1 | Advanced problems on Operators and Math.h function in C

  • 1. Structured Programming Language # include <math.h> Mohammad Imam Hossain, Lecturer, CSE, UIU Advanced problems on Operators
  • 2. Flow Chart โ€ข This whole slide is based on the following flow chart:
  • 3. # include <math.h> The math.h header declares a set of functions to compute common mathematical operations and transformations. Ref: MathDotH.pdf โ€œ Computers are good at following instructions, but not at reading your mind. โ€ - Donald Knuth
  • 4. Problem โ€ข Input: x (double) โ€ข Output: y (double) ๐‘ฆ = 5๐‘ฅ4 + 3๐‘ฅ2 + 7 tan ๐‘ฅ โˆ’ ๐‘’ ๐‘ฅ + ๐‘ฅ
  • 5. Solution ๐‘ฆ = 5๐‘ฅ4 + 3๐‘ฅ2 + 7 tan ๐‘ฅ โˆ’ ๐‘’ ๐‘ฅ + ๐‘ฅ#include <stdio.h> int main() { return 0; }
  • 6. Solution ๐‘ฆ = 5๐‘ฅ4 + 3๐‘ฅ2 + 7 tan ๐‘ฅ โˆ’ ๐‘’ ๐‘ฅ + ๐‘ฅ#include <stdio.h> int main() { double x,y; ///variable declaration return 0; }
  • 7. Solution ๐‘ฆ = 5๐‘ฅ4 + 3๐‘ฅ2 + 7 tan ๐‘ฅ โˆ’ ๐‘’ ๐‘ฅ + ๐‘ฅ#include <stdio.h> int main() { double x,y; ///variable declaration printf("Please enter the value of x: "); scanf(" %lf",&x); ///taking input the value of x return 0; }
  • 8. Solution ๐‘ฆ = 5๐‘ฅ4 + 3๐‘ฅ2 + 7 tan ๐‘ฅ โˆ’ ๐‘’ ๐‘ฅ + ๐‘ฅ#include <stdio.h> #include <math.h> int main() { double x,y; ///variable declaration printf("Please enter the value of x: "); scanf(" %lf",&x); ///taking input the value of x y=5*pow(x,4)+3*x*x+sqrt(7)*tan(x)-exp(x)+ceil(fabs(x)); ///Processing return 0; }
  • 9. Solution ๐‘ฆ = 5๐‘ฅ4 + 3๐‘ฅ2 + 7 tan ๐‘ฅ โˆ’ ๐‘’ ๐‘ฅ + ๐‘ฅ#include <stdio.h> #include <math.h> int main() { double x,y; ///variable declaration printf("Please enter the value of x: "); scanf(" %lf",&x); ///taking input the value of x y=5*pow(x,4)+3*x*x+sqrt(7)*tan(x)-exp(x)+ceil(fabs(x)); ///Processing printf("The resulting value is %lfn",y); ///printing output return 0; }
  • 10. Practice โ€ข Input: a (double), b(double) , c(double) โ€ข Output: x (double) ๐‘ฅ = 5๐‘Ž2 + 6๐‘ + ๐‘ 2๐‘Ž + ๐‘
  • 11. Problem โ€ข Input: p (integer, no of watts of a light), t (double, no of hours it is turned on) โ€ข Output: no of B.O.T units in kwh format.
  • 12. Problem โ€ข Input: p (integer, no of watts of a light), t (double, no of hours it is turned on) โ€ข Output: no of B.O.T units in kwh format. units = ๐‘๐‘ก 1000 ๐พ๐‘Š๐ป
  • 13. Code Sample #include <stdio.h> int main() { return 0; }
  • 14. Code Sample #include <stdio.h> int main() { double p,t,result; printf("Enter the power(in watts) & used time(in hours): "); scanf("%lf %lf",&p,&t); ///taking input return 0; }
  • 15. Code Sample #include <stdio.h> int main() { double p,t,result; printf("Enter the power(in watts) & used time(in hours): "); scanf("%lf %lf",&p,&t); ///taking input result=p*t/1000; ///calculating no of units return 0; }
  • 16. Code Sample #include <stdio.h> int main() { double p,t,result; printf("Enter the power(in watts) & used time(in hours): "); scanf("%lf %lf",&p,&t); ///taking input result=p*t/1000; ///calculating no of units printf("No of units: %.2lfn",result); ///output return 0; }
  • 17. Problem โ€ข Write a program that will initialize two integer types of variables (a ,b) and interchange(swap) the values between them and finally show the output. โ€ข Input: a=10, b=20 โ€ข Output: a=20, b=10
  • 18. Code Sample #include <stdio.h> int main() { return 0; }
  • 19. Code Sample #include <stdio.h> int main() { int a,b; scanf("%d %d",&a,&b); ///taking inputs return 0; }
  • 20. Code Sample #include <stdio.h> int main() { int a,b; scanf("%d %d",&a,&b); ///taking inputs int temp; /// to hold temporary value temp=a; /// saving a into temp return 0; }
  • 21. Code Sample #include <stdio.h> int main() { int a,b; scanf("%d %d",&a,&b); ///taking inputs int temp; /// to hold temporary value temp=a; /// saving a into temp a=b; ///now a has the new value of b return 0; }
  • 22. Code Sample #include <stdio.h> int main() { int a,b; scanf("%d %d",&a,&b); ///taking inputs int temp; /// to hold temporary value temp=a; /// saving a into temp a=b; ///now a has the new value of b b=temp; ///now b has the value of temp(old value of a) return 0; }
  • 23. Code Sample #include <stdio.h> int main() { int a,b; scanf("%d %d",&a,&b); ///taking inputs int temp; /// to hold temporary value temp=a; /// saving a into temp a=b; ///now a has the new value of b b=temp; ///now b has the value of temp(old value of a) printf("a=%d and b=%dn",a,b); ///output return 0; }
  • 24. Problem โ€ข Input: temperature(double) in ยฐC format. โ€ข Output: temperature(double) in ยฐF format.
  • 25. Problem โ€ข Input: temperature(double) in ยฐC format. โ€ข Output: temperature(double) in ยฐF format. ๐ถ โˆ’ 0 100 โˆ’ 0 = ๐น โˆ’ 32 212 โˆ’ 32
  • 26. Code Sample #include <stdio.h> int main() { return 0; }
  • 27. Code Sample #include <stdio.h> int main() { double c,f; printf("Enter temperature in Celsius: "); scanf("%lf",&c); ///taking input Celsius scale temperature return 0; }
  • 28. Code Sample #include <stdio.h> int main() { double c,f; printf("Enter temperature in Celsius: "); scanf("%lf",&c); ///taking input Celsius scale temperature f= 9*c/5+32; /// processing return 0; }
  • 29. Code Sample #include <stdio.h> int main() { double c,f; printf("Enter temperature in Celsius: "); scanf("%lf",&c); ///taking input Celsius scale temperature f= 9*c/5+32; /// processing printf("%.2lf Celsius = %.2lf Fahrenheit",c,f); ///output return 0; }
  • 30. Problem โ€ข Input: r (double, radius), h (double, height) โ€ข Output: the volume of a sphere
  • 31. Problem โ€ข Input: r (double, radius), h (double, height) โ€ข Output: the volume of a sphere ๐œ‹๐‘Ÿ2โ„Ž
  • 32. Code Sample #include <stdio.h> int main() { return 0; }
  • 33. Code Sample #include <stdio.h> int main() { double radius,height,volume; printf("please enter the radius and height of a cylinder: "); scanf("%lf %lf",&radius,&height); ///taking inputs return 0; }
  • 34. Code Sample #include <stdio.h> #define PI 3.1416 int main() { double radius,height,volume; printf("please enter the radius and height of a cylinder: "); scanf("%lf %lf",&radius,&height); ///taking inputs volume = PI*radius*radius*height; ///calculating volume return 0; }
  • 35. Code Sample #include <stdio.h> #define PI 3.1416 int main() { double radius,height,volume; printf("please enter the radius and height of a cylinder: "); scanf("%lf %lf",&radius,&height); ///taking inputs volume = PI*radius*radius*height; ///calculating volume printf("The volume of cylinder is %.3lfn",volume); ///output return 0; }
  • 36. Problem โ€ข Input: 6 floating point numbers (x1, y1), (x2, y2), (x3, y3) โ€ข Output: area (double, area of a triangle) (๐‘ฅ1, ๐‘ฆ1) (๐‘ฅ2, ๐‘ฆ2) (๐‘ฅ3, ๐‘ฆ3)
  • 37. Problem โ€ข Input: 6 floating point numbers (x1, y1), (x2, y2), (x3, y3) โ€ข Output: area (double, area of a triangle) (๐‘ฅ1, ๐‘ฆ1) (๐‘ฅ2, ๐‘ฆ2) (๐‘ฅ3, ๐‘ฆ3) ๐‘Ž๐‘Ÿ๐‘’๐‘Ž = 1 2 ๐‘ฅ1 โˆ’ ๐‘ฅ2 โˆ— ๐‘ฆ2 โˆ’ ๐‘ฆ3 โˆ’ ๐‘ฆ1 โˆ’ ๐‘ฆ2 โˆ— ๐‘ฅ2 โˆ’ ๐‘ฅ3 = 1 2 [๐‘ฅ1 โˆ— ๐‘ฆ2 โˆ’ ๐‘ฆ3 + ๐‘ฅ2 โˆ— ๐‘ฆ3 โˆ’ ๐‘ฆ1 + ๐‘ฅ3 โˆ— ๐‘ฆ1 โˆ’ ๐‘ฆ2 ]
  • 38. Code Sample#include <stdio.h> int main() { return 0; }
  • 39. Code Sample#include <stdio.h> int main() { double x1,y1,x2,y2,x3,y3; printf("Enter the 3 vertices of a triangle: "); scanf("%lf %lf",&x1,&y1); scanf("%lf %lf",&x2,&y2); scanf("%lf %lf",&x3,&y3); ///taking input return 0; }
  • 40. Code Sample#include <stdio.h> #include <math.h> ///for function fabs int main() { double x1,y1,x2,y2,x3,y3; printf("Enter the 3 vertices of a triangle: "); scanf("%lf %lf",&x1,&y1); scanf("%lf %lf",&x2,&y2); scanf("%lf %lf",&x3,&y3); ///taking input double area; area=0.5*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2));///calculating return 0; }
  • 41. Code Sample#include <stdio.h> #include <math.h> ///for function fabs int main() { double x1,y1,x2,y2,x3,y3; printf("Enter the 3 vertices of a triangle: "); scanf("%lf %lf",&x1,&y1); scanf("%lf %lf",&x2,&y2); scanf("%lf %lf",&x3,&y3); ///taking input double area; area=0.5*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2));///calculating printf("The area is %.3lf sq units.nโ€œ,fabs(area));///outputs return 0; }
  • 42. Practice โ€ข Input: a , b (base and height of a right angle triangle) โ€ข Output: the value of the hypotenuse
  • 43. Practice โ€ข Input: a , b (base and height of a right angle triangle) โ€ข Output: the value of the hypotenuse โ„Ž๐‘ฆ๐‘ = ๐‘๐‘Ž๐‘ ๐‘’2 + โ„Ž๐‘’๐‘–๐‘”โ„Ž๐‘ก2 base hypotenuse height
  • 44. Problem โ€ข Input: t (integer, time in seconds) โ€ข Output: ddd days hh hours mm minutes and ss seconds โ€ข Sample I/O: Input: 123456 Output: 001 days 10 hours 17 minutes and 36 seconds โ€œ First, solve the problem. Then, write the code. โ€ - John Johnson
  • 45. Code Sample#include <stdio.h> int main() { return 0; }
  • 46. Code Sample#include <stdio.h> int main() { int input; scanf("%d",&input); ///taking input return 0; }
  • 47. Code Sample#include <stdio.h> int main() { int input; scanf("%d",&input); ///taking input int day,hr,min,sec,rem_sec; return 0; }
  • 48. Code Sample#include <stdio.h> int main() { int input; scanf("%d",&input); ///taking input int day,hr,min,sec,rem_sec; day=input/(24*60*60); ///calculating no of days rem_sec=input%(24*60*60); ///the remaining seconds return 0; }
  • 49. Code Sample#include <stdio.h> int main() { int input; scanf("%d",&input); ///taking input int day,hr,min,sec,rem_sec; day=input/(24*60*60); ///calculating no of days rem_sec=input%(24*60*60); ///the remaining seconds hr=rem_sec/(60*60); ///calculating no of hours rem_sec=rem_sec%(60*60); ///remaining seconds return 0; }
  • 50. Code Sample#include <stdio.h> int main() { int input; scanf("%d",&input); ///taking input int day,hr,min,sec,rem_sec; day=input/(24*60*60); ///calculating no of days rem_sec=input%(24*60*60); ///the remaining seconds hr=rem_sec/(60*60); ///calculating no of hours rem_sec=rem_sec%(60*60); ///remaining seconds min=rem_sec/60; ///calculating no of minutes sec=rem_sec%60; ///final remaining seconds return 0; }
  • 51. Code Sample#include <stdio.h> int main() { int input; scanf("%d",&input); ///taking input int day,hr,min,sec,rem_sec; day=input/(24*60*60); ///calculating no of days rem_sec=input%(24*60*60); ///the remaining seconds hr=rem_sec/(60*60); ///calculating no of hours rem_sec=rem_sec%(60*60); ///remaining seconds min=rem_sec/60; ///calculating no of minutes sec=rem_sec%60; ///final remaining seconds printf("%03d days %02d hours %02d minutes and %02d seconds",day,hr,min,sec); ///output return 0; }
  • 52. Problem โ€ข Input: an integer of exactly 4 digits (for example, 1234) โ€ข Output: 1 thousands, 2 hundreds and 34
  • 53. Code Sample#include <stdio.h> int main() { return 0; }
  • 54. Code Sample#include <stdio.h> int main() { int num; scanf("%4d",&num); ///taking input return 0; }
  • 55. Code Sample#include <stdio.h> int main() { int num; scanf("%4d",&num); ///taking input int thous,hund,rem,temp; ///declaring variables return 0; }
  • 56. Code Sample#include <stdio.h> int main() { int num; scanf("%4d",&num); ///taking input int thous,hund,rem,temp; ///declaring variables thous=num/1000; /// calculating thousands temp=num%1000; /// remaining amounts return 0; }
  • 57. Code Sample#include <stdio.h> int main() { int num; scanf("%4d",&num); ///taking input int thous,hund,rem,temp; ///declaring variables thous=num/1000; /// calculating thousands temp=num%1000; /// remaining amounts hund=temp/100; ///calculating hundreds rem=temp%100; ///final remaining amounts return 0; }
  • 58. Code Sample#include <stdio.h> int main() { int num; scanf("%4d",&num); ///taking input int thous,hund,rem,temp; ///declaring variables thous=num/1000; /// calculating thousands temp=num%1000; /// remaining amounts hund=temp/100; ///calculating hundreds rem=temp%100; ///final remaining amounts printf("%d thousands, %d hundreds and %dn",thous,hund,rem); ///output return 0; }
  • 59. Practice โ€ข Input: an integer of exactly 4 digits (let, 1234) โ€ข Output: the sum of the digits (10)
  • 60. Problem โ€ข Input: a, b, c of the equation ๐‘Ž๐‘ฅ2 + ๐‘๐‘ฅ + ๐‘ = 0 โ€ข Output: the roots of this equation.
  • 61. Problem โ€ข Input: a, b, c of the equation ๐‘Ž๐‘ฅ2 + ๐‘๐‘ฅ + ๐‘ = 0 โ€ข Output: the roots of this equation. ๐‘ฅ1 = โˆ’๐‘ + ๐‘2 โˆ’ 4๐‘Ž๐‘ 2๐‘Ž ๐‘ฅ2 = โˆ’๐‘ โˆ’ ๐‘2 โˆ’ 4๐‘Ž๐‘ 2๐‘Ž
  • 62. Code Sample #include <stdio.h> #include <math.h> int main() { return 0; }
  • 63. Code Sample #include <stdio.h> #include <math.h> int main() { int a,b,c; ///ax^2+bx+c=0, coefficient input scanf("%d %d %d",&a,&b,&c); return 0; }
  • 64. Code Sample #include <stdio.h> #include <math.h> int main() { int a,b,c; ///ax^2+bx+c=0, coefficient input scanf("%d %d %d",&a,&b,&c); double x1,x2; ///roots calculation x1=(-b+sqrt(b*b-4*a*c))/(2*a); x2=(-b-sqrt(b*b-4*a*c))/(2*a); return 0; }
  • 65. Code Sample #include <stdio.h> #include <math.h> int main() { int a,b,c; ///ax^2+bx+c=0, coefficient input scanf("%d %d %d",&a,&b,&c); double x1,x2; ///roots calculation x1=(-b+sqrt(b*b-4*a*c))/(2*a); x2=(-b-sqrt(b*b-4*a*c))/(2*a); printf("Solutions are %lf and %lfn",x1,x2); ///output return 0; }
  • 66. Practice โ€ข Input: a1, b1, c1 and a2, b2, c2 where, ๐‘Ž1 ๐‘ฅ + ๐‘1 ๐‘ฆ + ๐‘1 = 0 ๐‘Ž2 ๐‘ฅ + ๐‘2 ๐‘ฆ + ๐‘2 = 0 โ€ข Output: the intersection point of that two straight lines.
  • 67. Practice โ€ข Input: a1, b1, c1 and a2, b2, c2 where, ๐‘Ž1 ๐‘ฅ + ๐‘1 ๐‘ฆ + ๐‘1 = 0 ๐‘Ž2 ๐‘ฅ + ๐‘2 ๐‘ฆ + ๐‘2 = 0 โ€ข Output: the intersection point of that two straight lines. ๐‘ฅ = ๐‘1 ๐‘2 โˆ’ ๐‘2 ๐‘1 ๐‘Ž1 ๐‘2 โˆ’ ๐‘Ž2 ๐‘1 ๐‘ฆ = ๐‘1 ๐‘Ž2 โˆ’ ๐‘2 ๐‘Ž1 ๐‘Ž1 ๐‘2 โˆ’ ๐‘Ž2 ๐‘1
  • 69. Practice โ€ข Input: two integers indicating the hours and minutes of an analog clock โ€ข Output: the angle between the two indicators.
  • 70. Problem โ€ข Input: 3 angles(double) of a triangle. โ€ข Output: a character โ€˜Yโ€™ (if valid triangle) โ€˜Nโ€™ (if not a valid triangle) A B C A+B+C = ๐œ‹
  • 71. Code Sample #include <stdio.h> int main() { double A,B,C; scanf("%lf %lf %lf",&A,&B,&C); char result; result=(A+B+C-180.0 < 0.00000001)?'Y':'N'; printf("%cn",result); return 0; }
  • 72. Practice โ€ข Input: 3 double numbers from the user โ€ข Output: average (double) of that 3 numbers. Sample I/O: โ€ข Input: 10.0,20.0,30.0 โ€ข Output: 20.000000
  • 73. Practice โ€ข Input: Grade points(double) of 6 subjects and their corresponding credit hours(double). โ€ข Output: weighted GPA ๐บ๐‘ƒ๐ด = ฯƒ๐‘–=1 ๐‘› ๐ถ๐‘– โˆ— ๐บ๐‘– ฯƒ๐‘–=1 ๐‘› ๐ถ๐‘–
  • 74. Course Credits, ๐‘ช๐’Š Grade Points, ๐‘ฎ๐’Š ๐‘ช๐’Š * ๐‘ฎ๐’Š CSE 100 2.00 4.00 8.00 EEE 163 3.00 4.00 12.00 EEE 164 1.50 3.75 5.625 MATH 141 3.00 3.00 9.00 ME 160 1.50 3.50 5.250 ME 165 3.00 4.00 12.00 PHY 109 4.00 3.75 15.00 PHY 102 1.50 3.50 5.250 Total 19.50 72.125 GPA calculation ๐บ๐‘ƒ๐ด = 72.125 19.50 = 3.7
  • 75. Practice โ€ข Input: Total credits(double) of 4 semesters and their corresponding GPA(double) earned. โ€ข Output: Cumulative GPA C๐บ๐‘ƒ๐ด = ฯƒ๐‘–=1 ๐‘› ๐‘‡๐ถ๐‘– โˆ— ๐บ๐‘ƒ๐ด๐‘– ฯƒ๐‘–=1 ๐‘› ๐‘‡๐ถ๐‘–
  • 76. Semester Total Credits, ๐“๐‘ช๐’Š GPA earned, ๐‘ฎ๐‘ท๐‘จ๐’Š ๐‘ป๐‘ช๐’Š * ๐‘ฎ๐‘ท๐‘จ๐’Š 1 19.50 3.70 72.150 2 20.50 3.93 80.565 3 21.25 3.96 84.150 4 20.25 4.00 81.00 Total 81.50 317.865 CGPA calculation ๐ถ๐บ๐‘ƒ๐ด = 317.865 81.50 = 3.90