CMIS102 C Programming Lab: Integer and Decimal Operations
VerifiedAdded on  2022/09/06
|11
|1382
|18
Practical Assignment
AI Summary
This document presents a comprehensive solution to a C programming lab assignment, focusing on fundamental arithmetic operations. The assignment covers the creation of C code to perform addition, multiplication, and division with integers, as well as the summation of decimal numbers. The solution includes the program description, analysis, program design (with pseudocode), and a detailed test plan with expected outputs for various inputs, along with screenshots of successful test runs. The C code is provided with comments explaining each step, from variable declaration and initialization to user input and output formatting. The solution also addresses potential edge cases, such as division by zero, and includes examples of the code execution with different input values to demonstrate the functionality. This document is designed to help students understand and implement C programs for basic arithmetic operations and is available on Desklib, a platform providing AI-based study tools for students.

Running head: C PROGRAMMING
C PROGRAMMING
Enter the name of the Student:
Enter the name of the University:
Author note:
C PROGRAMMING
Enter the name of the Student:
Enter the name of the University:
Author note:
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

1C PROGRAMMING
1.
Run# Input (x) Input (y) Expected Output
1 10 20 30
2 0 0 0
3 124 356 480
4 -30 -90 -120
The screenshots of these above successful tests are as follows:
Figure 1: Test 1 of addition
(Source: Created by author)
Figure 2: Test 2 of addition
1.
Run# Input (x) Input (y) Expected Output
1 10 20 30
2 0 0 0
3 124 356 480
4 -30 -90 -120
The screenshots of these above successful tests are as follows:
Figure 1: Test 1 of addition
(Source: Created by author)
Figure 2: Test 2 of addition

2C PROGRAMMING
(Source: Created by author)
Figure 3: Test 3 of addition
(Source: Created by author)
Figure 4: Test 4 of addition
(Source: Created by author)
2. The C code to calculate the product of two integers is as follows:
// C code
// This program will product two integer numbers to yield a third integer number.
// Developer: Faculty CMIS102
(Source: Created by author)
Figure 3: Test 3 of addition
(Source: Created by author)
Figure 4: Test 4 of addition
(Source: Created by author)
2. The C code to calculate the product of two integers is as follows:
// C code
// This program will product two integer numbers to yield a third integer number.
// Developer: Faculty CMIS102
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

3C PROGRAMMING
// Date: Jan 31, XXXX
#include <stdio.h>
int main ()
{
int x, y, z; /* variable definition: */
x = 0; y = 0; /* variable initialization */
printf("Developer: Faculty CMIS102 ");
printf("Date: Jan 31, 2020");
printf("\n enter a value for x: \t"); //Prompt for user input
scanf("%d" , &x); //Get the user response
printf("\n enter a value for y: \t"); //Prompt for user input
scanf("%d", &y); //Get the user response
z = x * y; //Calculate the product
//Print out the answer
//Note: x,y,z are Declared as Integer, hence we use %d as the formatter.
//Wherever you put the formatter symbol (i.e %d) is where the variable value is substituted.
//The order of the substitution is the same as the order of the variable list at the end (a,b,c)
//Note the tab (\t) in the statement also.
printf("\n\n The product of Integers (%d) and (%d) is : \t %d \n", x, y, z);
// value of x is substituted here ^ value of y ^ value z ^ here
// Date: Jan 31, XXXX
#include <stdio.h>
int main ()
{
int x, y, z; /* variable definition: */
x = 0; y = 0; /* variable initialization */
printf("Developer: Faculty CMIS102 ");
printf("Date: Jan 31, 2020");
printf("\n enter a value for x: \t"); //Prompt for user input
scanf("%d" , &x); //Get the user response
printf("\n enter a value for y: \t"); //Prompt for user input
scanf("%d", &y); //Get the user response
z = x * y; //Calculate the product
//Print out the answer
//Note: x,y,z are Declared as Integer, hence we use %d as the formatter.
//Wherever you put the formatter symbol (i.e %d) is where the variable value is substituted.
//The order of the substitution is the same as the order of the variable list at the end (a,b,c)
//Note the tab (\t) in the statement also.
printf("\n\n The product of Integers (%d) and (%d) is : \t %d \n", x, y, z);
// value of x is substituted here ^ value of y ^ value z ^ here
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

4C PROGRAMMING
return 0;
}
3.
Run# Input (x) Input (y) Expected Output
1 15 2 30
2 3 9 27
3 12 356 4272
The screenshots of these above successful tests are as follows:
Figure 5: Test 1 for multiplication
(Source: Created by author)
return 0;
}
3.
Run# Input (x) Input (y) Expected Output
1 15 2 30
2 3 9 27
3 12 356 4272
The screenshots of these above successful tests are as follows:
Figure 5: Test 1 for multiplication
(Source: Created by author)

5C PROGRAMMING
Figure 6: Test 2 for multiplication
(Source: Created by author)
Figure 7: Test 3 for multiplication
(Source: Created by author)
4. The C code to calculate the quotient of two integers is as follows:
// C code
// This program will quotient two integer numbers to yield a third integer number.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
int main ()
{
int x, y; /* variable definition: */
Figure 6: Test 2 for multiplication
(Source: Created by author)
Figure 7: Test 3 for multiplication
(Source: Created by author)
4. The C code to calculate the quotient of two integers is as follows:
// C code
// This program will quotient two integer numbers to yield a third integer number.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
int main ()
{
int x, y; /* variable definition: */
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

6C PROGRAMMING
float z;
x = 0; y = 0; /* variable initialization */
printf("Developer: Faculty CMIS102 ");
printf("Date: Jan 31, 2020");
printf("\n enter a value for x: \t"); //Prompt for user input
scanf("%d" , &x); //Get the user response
printf("\n enter a value for y: \t"); //Prompt for user input
scanf("%d", &y); //Get the user response
z = (float)x / (float)y; //Calculate the quotient
//Print out the answer
//Note: x,y,z are Declared as Integer, hence we use %d as the formatter.
//Wherever you put the formatter symbol (i.e %d) is where the variable value is substituted.
//The order of the substitution is the same as the order of the variable list at the end (a,b,c)
//Note the tab (\t) in the statement also.
printf("\n\n The quotient of Integers (%d) and (%d) is : \t %.1f \n", x, y, z);
// value of x is substituted here ^ value of y ^ value z ^ here
return 0;
}
a)
Run# Input (x) Input (y) Expected Output
float z;
x = 0; y = 0; /* variable initialization */
printf("Developer: Faculty CMIS102 ");
printf("Date: Jan 31, 2020");
printf("\n enter a value for x: \t"); //Prompt for user input
scanf("%d" , &x); //Get the user response
printf("\n enter a value for y: \t"); //Prompt for user input
scanf("%d", &y); //Get the user response
z = (float)x / (float)y; //Calculate the quotient
//Print out the answer
//Note: x,y,z are Declared as Integer, hence we use %d as the formatter.
//Wherever you put the formatter symbol (i.e %d) is where the variable value is substituted.
//The order of the substitution is the same as the order of the variable list at the end (a,b,c)
//Note the tab (\t) in the statement also.
printf("\n\n The quotient of Integers (%d) and (%d) is : \t %.1f \n", x, y, z);
// value of x is substituted here ^ value of y ^ value z ^ here
return 0;
}
a)
Run# Input (x) Input (y) Expected Output
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

7C PROGRAMMING
1 7 3 2.33
2 13 5 2.6
The screenshots of these above successful tests are as follows:
Figure 8: Test 1 for quotient
(Source: Created by author)
Figure 8: Test 2 for quotient
(Source: Created by author)
b) if the denominator is 0, then the quotient is infinite. The screenshot of this situation is as
follows:
1 7 3 2.33
2 13 5 2.6
The screenshots of these above successful tests are as follows:
Figure 8: Test 1 for quotient
(Source: Created by author)
Figure 8: Test 2 for quotient
(Source: Created by author)
b) if the denominator is 0, then the quotient is infinite. The screenshot of this situation is as
follows:

8C PROGRAMMING
Figure 9: Test 3 for quotient
(Source: Created by author)
5. The C code to input three decimal numbers that is floats is as follows:
// C code
// This program will sum three decimal numbers to yield a forth decimal number.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
int main ()
{
float x, y, z; /* variable definition: */
float a;
x = 0.0; y = 0.0; z = 0.0; /* variable initialization */
printf("Developer: Faculty CMIS102 ");
printf("Date: Jan 31, 2020");
Figure 9: Test 3 for quotient
(Source: Created by author)
5. The C code to input three decimal numbers that is floats is as follows:
// C code
// This program will sum three decimal numbers to yield a forth decimal number.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
int main ()
{
float x, y, z; /* variable definition: */
float a;
x = 0.0; y = 0.0; z = 0.0; /* variable initialization */
printf("Developer: Faculty CMIS102 ");
printf("Date: Jan 31, 2020");
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

9C PROGRAMMING
printf("\n enter a value for x: \t"); //Prompt for user input
scanf("%f" , &x); //Get the user response
printf("\n enter a value for y: \t"); //Prompt for user input
scanf("%f", &y); //Get the user response
printf("\n enter a value for y: \t"); //Prompt for user input
scanf("%f", &z); //Get the user response
a = x + y + z; //Calculate the quotient
//Print out the answer
//Note: x,y,z are Declared as float, hence we use %f as the formatter.
//Wherever you put the formatter symbol (i.e %f) is where the variable value is substituted.
//The order of the substitution is the same as the order of the variable list at the end (a,b,c)
//Note the tab (\t) in the statement also.
printf("\n\n The quotient of decimals (%f), (%f) and (%f) is : \t %f \n", x, y, z, a);
return 0;
}
6.
Run# Input (x) Input (y) Input (z) Expected Output
1 13.5 5.60 4.08 23.18
2 3.78 9.14 6.71 19.63
3 12.04 35.60 74.61 122.25
printf("\n enter a value for x: \t"); //Prompt for user input
scanf("%f" , &x); //Get the user response
printf("\n enter a value for y: \t"); //Prompt for user input
scanf("%f", &y); //Get the user response
printf("\n enter a value for y: \t"); //Prompt for user input
scanf("%f", &z); //Get the user response
a = x + y + z; //Calculate the quotient
//Print out the answer
//Note: x,y,z are Declared as float, hence we use %f as the formatter.
//Wherever you put the formatter symbol (i.e %f) is where the variable value is substituted.
//The order of the substitution is the same as the order of the variable list at the end (a,b,c)
//Note the tab (\t) in the statement also.
printf("\n\n The quotient of decimals (%f), (%f) and (%f) is : \t %f \n", x, y, z, a);
return 0;
}
6.
Run# Input (x) Input (y) Input (z) Expected Output
1 13.5 5.60 4.08 23.18
2 3.78 9.14 6.71 19.63
3 12.04 35.60 74.61 122.25
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

10C PROGRAMMING
The screenshots of these above successful tests are as follows:
Figure 10: Test 1 for sum of three decimal numbers
(Source: Created by author)
Figure 11: Test 2 for sum of three decimal numbers
(Source: Created by author)
Figure 12: Test 3 for sum of three decimal numbers
(Source: Created by author)
The screenshots of these above successful tests are as follows:
Figure 10: Test 1 for sum of three decimal numbers
(Source: Created by author)
Figure 11: Test 2 for sum of three decimal numbers
(Source: Created by author)
Figure 12: Test 3 for sum of three decimal numbers
(Source: Created by author)
1 out of 11
Related Documents

Your All-in-One AI-Powered Toolkit for Academic Success.
 +13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.