Sei sulla pagina 1di 21

Problem Solving and Program Design in C

(5th Edition)

by Jeri R. Hanly and Elliot B. Koffman

CP 202
Chapter 3 (Appendix)
Slides By
Dr. Daniyal Alghazzawi
#include <stdio.h>
#define first 0
#define second 9
int job1(int x, int y)
{
int total;
total = x+y;
return (total); Question:
}
int job2(int x)
{ Show the output of this
return (first * x); program including all the
}
int job3(int x) values in the memory?
{
return (second * x);
}
int main(void)
{
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
*/
int first_digit;
int last_digit;
int total;
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
scanf("%d", &last_digit);
total = job1(first_digit, last_digit);
printf("Job 1 = %d\n", total);
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS
#define second 9
int job1(int x, int y) first second
{ 0 9
int total;
total = x+y;
return (total);
}
int job2(int x)
{
return (first * x);
}
int job3(int x)
{
return (second * x);
}
int main(void)
{
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
*/
int first_digit;
int last_digit;
int total;
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
scanf("%d", &last_digit);
total = job1(first_digit, last_digit);
printf("Job 1 = %d\n", total);
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
total = x+y; )
return (total);
}
int job2(int x)
{
return (first * x);
}
int job3(int x)
{
return (second * x);
}
int main(void)
{
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
*/
int first_digit;
int last_digit;
int total;
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
scanf("%d", &last_digit);
total = job1(first_digit, last_digit);
printf("Job 1 = %d\n", total);
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
}
int main(void)
{
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
*/
int first_digit;
int last_digit;
int total;
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
scanf("%d", &last_digit);
total = job1(first_digit, last_digit);
printf("Job 1 = %d\n", total);
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
*/
int first_digit;
int last_digit;
int total;
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
scanf("%d", &last_digit);
total = job1(first_digit, last_digit);
printf("Job 1 = %d\n", total);
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit);
printf("Job 1 = %d\n", total);
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID:
printf("Job 1 = %d\n", total);
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
printf("Job 1 = %d\n", total);
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
printf("Job 1 = %d\n", total); Enter the last digit of your ID:
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1 7
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
printf("Job 1 = %d\n", total); Enter the last digit of your ID: 7
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1 7
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
Call function scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
printf("Job 1 = %d\n", total); Enter the last digit of your ID: 7
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
1 7
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1 7
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
printf("Job 1 = %d\n", total); Enter the last digit of your ID: 7
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
1 7 8
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1 7
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
printf("Job 1 = %d\n", total); Enter the last digit of your ID: 7
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
1 7 8
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1 7 8
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
printf("Job 1 = %d\n", total); Enter the last digit of your ID: 7
total = job2(last_digit);
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
1 7 8
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1 7 8
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
printf("Job 1 = %d\n", total); Enter the last digit of your ID: 7
total = job2(last_digit); Job 1 = 8
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
1 7 8
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x)
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1 7 8
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
Call function printf("Job 1 = %d\n", total); Enter the last digit of your ID: 7
total = job2(last_digit); Job 1 = 8
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
1 7 8
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x) 7
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1 7 8
printf("Enter the first digit of your ID: ");
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
printf("Job 1 = %d\n", total); Enter the last digit of your ID: 7
total = job2(last_digit); Job 1 = 8
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
1 7 8
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x) 7
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1 7 8
printf("Enter the first digit of your ID: ");
0
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
printf("Job 1 = %d\n", total); Enter the last digit of your ID: 7
total = job2(last_digit); Job 1 = 8
printf("Job 2 = %d\n", total);
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
1 7 8
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x) 7
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1 7 8
printf("Enter the first digit of your ID: ");
0
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
printf("Job 1 = %d\n", total); Enter the last digit of your ID: 7
total = job2(last_digit); Job 1 = 8
printf("Job 2 = %d\n", total); Job 2 = 0
return(0);
}
#include <stdio.h>
#define first 0 Memory: CONSTANTS Memory: job1()
#define second 9
int job1(int x, int y) first second x y t
{ (int (int) otal
0 9
int total; ) (int
1 7 8
total = x+y; )
return (total);
} Memory: job2()
int job2(int x)
{ x
return (first * x); (int)
}
int job3(int x) 7
{
return (second * x);
} Memory: job3()
int main(void) x
{ (int)
/*
for example, if your ID is 1234567
first_digit = 1
last_digit = 7
Memory: main()
*/
int first_digit; first_di last_di tota
int last_digit; git git l
int total; (int) (int) (int)
1 7 8
printf("Enter the first digit of your ID: ");
0
scanf("%d", &first_digit);
printf("Enter the last digit of your ID: ");
Output:
scanf("%d", &last_digit);
total = job1(first_digit, last_digit); Enter the first digit of your ID: 1
printf("Job 1 = %d\n", total); Enter the last digit of your ID: 7
total = job2(last_digit); Job 1 = 8
Stop Program printf("Job 2 = %d\n", total); Job 2 = 0
return(0);
}

Potrebbero piacerti anche