Question
Need help coding these two C programs


1:27 LTE < s3?bucket-uploads&prefix-attach%2Fjl CS 100 Exam Two -Coding -Spring 2018 You are not allowed to use the Internet while coding the two problems below. You can log into the cs-intro server to test your programs if you wish When you have finished submit your exam via Blackboard Create a directory called exam2 using mkdir exan2 and move into that dinectory with ed exan2 Complete the I. Name this program one.c-This peogram reads insegers feom standand input until end-of-file (control-d) and wo peograms shown bekow arites them to either the file good or the file bad. Write the first mumber to the fle good. Afer that, as long as the number is larger than the one it read before (the peevious vallac) we that number to the file good wrine that number to the filk bad. Two sample esecutions are shown below good bad /a.out Enter your data 1 35 2 3 5 3 1 9 2 etri-d good bad Enter your data 20 15 10 30 40 30 20 90 20 30 40 90 15 10 30 20 2 Name this program two.c-This program reads rwo strings from standand input and uses a function to detenmine the number of common characters at the stant of the two strings For example, if the first string is computer and the second string is complex, then these two strings have4(our) ininial characters in common. Lakewise, if the two strings are Alabama and Auburn, them the ruo strings have 1 (one) inicial character in common. Finally, cat and catalog ould have 3 (throc) inicial characters in common. This function is case-sensitive, upper-case leters do not match their equialenr lower-case letner (the lemer A is different from the letter a). Use the template for two.e that is shown belorw to code your solution rie the function commonStart). #include <stdio.h> linclude <string.h> int commonStart (char int main (void) char [) char str1 [50. str2 [50] printf ( Enter two strings) scanf (%s %s, str1, str2); printf(nThere are d common letters at start of ts and taln commonStart (strl, str2), strl1, str2 return 0 First, on your local machine, compress your exam2 dinectoey inso a single (compressed) fle. Second, once you have a compressed fille named esam2zip,submit that file to Blackboand.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

one.c

#include<stdio.h>

int main(){

int n, prev = -1;

FILE *f1, *f2;

f1 = fopen("good", "w");

f2 = fopen("bad", "w");

printf("Enter your data: \n");

while(scanf("%d", &n)!=EOF){

if(n>=prev)

fprintf(f1, "%d\n", n);

else

fprintf(f2, "%d\n", n);

prev = n;

}

fclose(f1);

fclose(f2);

return 0;

}

nagarajuanagaraju-Vostro-3550:~/Desktop/CHEGG/october/12102018$./a.out Enter your data: 13 52 3 5 3 19 2 nagarajuanagaraju-Vostro-3550:~/Desktop/CHEGG/October/12102018$ cat./good 3 nagarajuanagaraju-Vostro-3550:~/Desktop/CHEGG/October/12102018$ cat./bad nagarajuanagaraju-Vostro-3550:~/Desktop/CHEGG/october/12102018$./a.out Enter your data: 20 15 10 30 40 30 20 90 1 nagarajuanagaraju-Vostro-3550:~/Desktop/CHEGG/October/12102018$ cat./good 20 30 40 90 nagarajuanagaraju-Vostro-3550:~/Desktop/CHEGG/October/12102018$ cat./bad 15 10 30 20

two.c

#include<stdio.h>

#include<string.h>

int commonStart(char [], char []);

int main(void){

char str1[50], str2[50];

printf("Enter two strings : ");

scanf("%s %s", str1, str2);

printf("\nThere are %d common letters at start of %s and %s\n\n", commonStart(str1, str2), str1, str2);

return 0;

}

int commonStart(char str1[], char str2[]){

int c=0;

while(str1[c]==str2[c]){

c++;

}

return c;

}

Add a comment
Know the answer?
Add Answer to:
Need help coding these two C programs 1:27 LTE < s3?bucket-uploads&prefix-attach%2Fjl CS 100 Exam Two -Coding...
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
  • Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You...

    Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You will place all of your function prototypes in a header file named string utils.h and all of your function definitions in a source file named string utils.c. You should implement your own main test driver program to test your functions, but you need not hand it in. a. void addChar(char *str, char c, int n) - this function should add a char c at...

  • Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description:...

    Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description: For this project you will write a program to: a) read-in the 10 first names from a file (the file is a priori given to have exactly 10 entries, of a maximum length of 8 letters each) into a 2-dimensional character array, b) output the names to the terminal with each one preceded by a number indicating its original order in the list, c)...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • I need help finding what is wrong with this code, it is for a CS course...

    I need help finding what is wrong with this code, it is for a CS course I am taking which codes in C (I am using XCode on Mac to code). This is the assignment: "Write a program that performs character processing on 10 characters read in from a file, and writes the results to output files. The program should read from “input.dat”. The program should write the ASCII values of the characters to “output_ascii.dat”. The program should print statistics...

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

  • Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C -...

    Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...

  • This assignment tests your ability to write C programs that handle keyboard input, formatted console output,...

    This assignment tests your ability to write C programs that handle keyboard input, formatted console output, and input/output with text files. The program also requires that you use ctype functions to deal with the logic. In this program, you will input from the user two characters, which should both be letters where the second letter > the first letter. You will then input a file character-by-character and output those letters that fall between the two characters (inclusively) to an output...

  • Hello! I'm posting this program that is partially completed if someone can help me out, I...

    Hello! I'm posting this program that is partially completed if someone can help me out, I will give you a good rating! Thanks, // You are given a partially completed program that creates a list of employees, like employees' record. // Each record has this information: employee's name, supervisors's name, department of the employee, room number. // The struct 'employeeRecord' holds information of one employee. Department is enum type. // An array of structs called 'list' is made to hold...

  • Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment...

    Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment 1 ID: 1. True / False 2. True / False 3. True / False 4. True / False 5. True / False 6. True / False 7. True / False 8. True / False 9. True / False 10. True / False Variable and functions identifiers can only begin with alphabet and digit. Compile time array sizes can be non-constant variables. Compile time array...

  • Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And...

    Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And also I have codes but just donot work so make sure that it works. Requested files: CrosswordGenerator.cpp, CrosswordGenerator.h, CrosswordGenerator_test.cpp CrosswordGenerator - Write a program that helps to generate a crossword puzzle by organizing words that share letters.   For this assignment, you will write a program that forms the basis of a crossword puzzle generator. In order to create a crossword puzzle you need to...

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