Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

we need to do this with C (please answer it only C). Here is testing code. #include #include a1_question1.h void checkAndPrint( unsigned int expected, unsigned

image text in transcribedwe need to do this with C (please answer it only C).

Here is testing code.

#include

#include "a1_question1.h"

void checkAndPrint(unsigned int expected, unsigned int result) {

if (expected == result) {

printf("%d is the same as %d, PASS ", expected, result);

} else {

printf("%d is not the same as %d, FAIL ", expected, result);

}

}

int main() {

checkAndPrint(131, insert_digit(1, 3)); //should return 131

checkAndPrint(2122232, insert_digit(2, 123)); //should return 2122232

checkAndPrint(40404040, insert_digit(0, 4444)); //should return 40404040 (no leading zero)

return 0;

}

and produces the required output. Also use the file names and structures indicated as requested. Deviation from that might result in 0 mark. Your code MUST compile and run in the CSIL machines with the Makefile provided. It is possible that even with warnings your code would compile. But this still indicates there is something wrong with you code and you have to fix them, or marks will be deducted. Your code MUST be readable and have reasonable documentation (comments) explaining what it does. Use your own judgement, for example, no need to explain i+=2 is increasing i by 2 , but explain how variables are used to achieve something, what a certain loop is doing, and the purpose of each \#include. Description There is a total of 3 questions in this assignment. For each question, write your answer in a single file that contains your student information. Unless otherwise specified, do not include any libraries. You can however write your own helper functions. Also do not print anything unless the question asks you to do so. None of these files should contain the main function. Question 1 [5 marks] Write a function that inserts a provided digit into a positive int up to 4 digits long and returns the result as a positive int with this rule: insert as first, third, fifth, ...etc. Use this function header: unsigned int insert_digit(unsigned int digit, unsigned int number) For example (you can assume the number does not have leading zeros, but the digit can be zero): insert_digit(1,3) should return 131

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

Discuss the objectives of discipline and appeals systems

Answered: 1 week ago