Question

Problem: Given an integer as input determine if the digits in a second integer appear in the first integer in the same orderPlease answer this questions in language C and make sure all executions work.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the C code as per mentioned problem statement:

#include<stdio.h>
#include<stdbool.h>

// Function for checking the target number is in order till now.
bool isInCorrectOrder(long a_num, long b_num){
bool isTrue=false;
long c_num=a_num;

while(b_num>0){
isTrue=false;
int digit=b_num%10;
while(c_num>0){
if(c_num%10==digit)
{
isTrue=true;
c_num=c_num/10;
break;
}
else c_num=c_num/10;
}
b_num=b_num/10;
if(!isTrue) {
isTrue= false;
break;
}
}
return isTrue;
}


// Main method execution will starts from here
void main(){
  
// using long for large number
long num_1,num_2;
printf("Enter data to search -> ");
scanf("%ld",&num_1);
printf("Enter target to locate -> ");
scanf("%ld",&num_2);
//   
long c_num = num_1;
long d_num = num_2;
int da = 0, db = 0;

while(c_num>0){
c_num = c_num/10;
da++;
}
while(d_num>0){
d_num = d_num/10;
db++;
}
// Check that numbers are in correct order till now
if(da>=db){

if(isInCorrectOrder(num_1,num_2)){
printf("\nTarget: %ld found",num_2);
}
else
{
while(!isInCorrectOrder(++num_1,num_2));
printf("\nNext value to contain target: %ld",num_1);
}
}
else printf("\nError! Number of digits in target cannot exceed.");

}

Please find the screenshot of the code and output:

main.c 1 #include<stdio.h> 2 #include<stdbool.h> 3 // Function for checking the target number is in order till now. 5. bool imain.c. 30 31 // Main method execution will starts from here 32 void main() { // using long for large number long num_1,num_2main.c long num_1,num_2; printf(Enter data to search -> ); scanf(%d,&num_1); printf(Enter target to locate -> ); scanf(

Enter data to search -> 123456 Enter target to locate -> 235 Target: 235 found

Enter data to search -> 125125 Enter target to locate -> 521 Next value to contain target: 125201

Enter data to search -> 9753108642 Enter target to locate -> 71999 Next value to contain target: 9753108999

Add a comment
Know the answer?
Add Answer to:
Please answer this questions in language C and make sure all executions work. Problem: Given an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write the code in C with all the right output please. Problem: In this assignment you...

    Write the code in C with all the right output please. Problem: In this assignment you will analyze a data set of 10,000 randomly generated integers. From this data set you will display a count of the prime numbers that are greater than the average (double) of the entire data set. The user will input only a single integer value to serve as the seed for the random number generator. The use of a common seed will result in output...

  • C programming. Write the code described in the picture with given 2 example executions of the...

    C programming. Write the code described in the picture with given 2 example executions of the code, and they must match. AND YOU CANT USE if statements! Problem: Allow the user to enter a positive integer value to represent the seed value for the random number generator. Next, generate a random integer that represents a possible number of points that a student may earn in a given class (0 to a maximum of 1000 possible points). Calculate the corresponding letter...

  • can someone please help me solve these problem in c++ language and leave useful comments below...

    can someone please help me solve these problem in c++ language and leave useful comments below so i can follow along and know what i am doing /view wa New Tab CSSO IDE 15 THE DIGIT SWAP PROBLEM Write a function named swapDigitPairs() that accepts a positive integer n as an input-output parameter which is changed to a new value similar to n's but with each pair of digits swapped in order. For example: int n = 482596; int old...

  • Please provide C language code no c++ ,txt file also needed with comment Finish task 5...

    Please provide C language code no c++ ,txt file also needed with comment Finish task 5 Task5: Breadth First Search (15 pts) · Write a program to read the graph information from the file and traverse the graph using BFS algorithm as introduced in lecture. The input for each algorithm is an undirected unweighted connected graph stored in a local file using an adjacency list. Following is the example of the input file (graph.txt) and the graph First line is...

  • For programming C language This problem will be briefly discussed in Lab2 and the TĀ will...

    For programming C language This problem will be briefly discussed in Lab2 and the TĀ will give you hints to solve it. However, the TĀ will not write the code. This code is a bit complicated, so try to understand the process from the TA so that you can continue working on it at home. Reverse the Number Write a program that takes a 5-digit number as input and print the reverse of the number. Sample Input/Output: Enter a five...

  • Programming language: Java Home Work No.2 due 09.11.2019 either ascending or descending SORTING: An array is...

    Programming language: Java Home Work No.2 due 09.11.2019 either ascending or descending SORTING: An array is said to be ordered if its values order. In an ascending ordered array, the value of each element is less than or equal to the value of the next element. That is, [each element] <= [next element]. A sort is an algorithm for ordering an array. Of the many different techniques for sorting an array we discuss the bubble sort It requires the swapping...

  • Write a MIPS assembly language program that uses dynamic memory allocation to create and manage a...

    Write a MIPS assembly language program that uses dynamic memory allocation to create and manage a linked list data structure. Gives the user the following options:                         1. To create and add the first node to a linked list.          2. To add a single node to the pre-existing linked list.             The list must already exist before a new node can be added.            The nodes should be maintained in ascending order based on the data value within the nodes...

  • Here is the code given for this problem: **And please do this in Python** def mergesort(mlist): if len(mlist)<2: ret...

    Here is the code given for this problem: **And please do this in Python** def mergesort(mlist): if len(mlist)<2: return mlist else: mid=len(mlist)//2 return merge(mergesort(mlist[:mid]),mergesort(mlist[mid:])) Problem 1 (30 points) stable merge sort Consider the following unsorted list of integers containing duplicates where the relative position of each duplicated integer in the unsorted list is noted as a subscript. For example, 1, is at a smaller index than 12. The subscript is ignored when comparing two values since it would not actually...

  • C programming question please meet all of the following conditions don't just output the same answer ​​​​​​​ Given a...

    C programming question please meet all of the following conditions don't just output the same answer ​​​​​​​ Given a sequence a. The elements of a has the following infomations: index The index is followed by the input order, starts from 1. The input won't contain index , you have to record it yourself. Smaller input index has higher priority. admin level : Level starts from 0 to 999. level 0 has the highest priority, while level 999 has the lowest....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT