Question:
Write C program to read two inputs
1. a string variable 's' and
2. a integer variable 'n'
C Program should concatenates s with itself with n-1 times if following conditions are satisfied
condition 1: s contains only 3 characters
condition 2: the first character in s is a letter
condition 3: s consists of letters (A-Z a-z) and digits only (0-9)
condition 4: n should be greater than 0 and lesser than 5
C Code as follows:
/* Include needed header files */
#include <stdio.h>
#include <string.h>
void str_cat(char *s1,int n1)
{
//store n-1 value into a variable limit
int limit = n1-1;
char final_str[100];
//first use string copy api to copy param from s1 to final_str
strcpy(final_str,s1);
for(int i = 0;i < limit;i++)
{
//store the concatenation string values to final_str
strcat(final_str,s1);
}
//copy back the concatenation string to the original string s1
strcpy(s1,final_str);
printf("Concatenated String is : %s and Temporary String is : %s", s1,final_str);
}
int main(void)
{
//string s - declaration
char s[100];
//int n - declaration
int n;
//Get the input string from User
printf("Enter the Input String:");
scanf("%s",&s);
//Get the integer number count From User
printf("Enter the Integer Number Count Integer Value");
scanf("%d",&n);
//store the first letter of string s to char variable c
char c = s[0];
/* do the below condition validation , if any condition validation fails return Error
condition 1: s contains only 3 characters
condition 2: the first character in s is a letter
condition 3: s consists of letters (A-Z a-z) and digits only (0-9)
condition 4: n should be greater than 0 and lesser than 5 */
if ((strlen(s) > 3) || ((n <= 0) || (n >= 5)) || (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))))
{
printf("ERROR IN INPUTS");
}
else
{
//do input string value concatenation till n-1 times
str_cat(s,n);
}
return 0;
}
Successful Output is :
Enter the Input String: Ab3
Enter the Integer Number Count Integer Value: 3
Concatenated String is : Ab3Ab3Ab3 and Temporary String is : Ab3Ab3Ab3
Err Output 1 is :
Enter the Input String: 3Ab
Enter the Integer Number Count Integer Value: 3
ERROR IN INPUTS
Error Output 2 is :
Enter the Input String: Ab3
Enter the Integer Number Count Integer Value: 0
ERROR IN INPUTS
Error Output 3 is :
Enter the Input String: Ab3
Enter the Integer Number Count Integer Value: 5
ERROR IN INPUTS
Please ran the program in C Compiler Compatible OS and give different inputs and check the output results.
Question 1: Consider the following specification for a program. The program reads two inputs from the...
6. Consider a C program that reads two real numbers from the keyboard followed by a character where the character can be one of the operators +,-, *, 1, or % providing the addition, subtraction, multiplication, division, or remainder respectively. Then the result is displayed on the screen For example, if the user types 2.0 3.0 % then your code will display: Note: In the above example the inputs are real numbers but the remainder only performs an integer operation....
Write MARIE assembly language programs that do the following: I. Write a program that inputs three integers, a, b, and c, in that order. It computes the following ia-bi-fc+ c The result should be written to output 2. Write a program that inputs integers, s. y, and z. It outputs the difference of the langest and first element entered. You may assume x. y, and z all have different values. So if 8, 12, and 9 are input, the output...
C Programming QUESTION 9 Write a program that prompts for and reads four integer input values, then a single character command. Submit your program as a .c file named midterm_prog2.c. Note that, similarly to your programming assignments, some percentage of your grade will depend on proper programming style. Your program will calculate and print a new value based on the command that's entered, as follows: 'A' or 'a': Calculate the average of the four input values 'S' or 's': Calculate...
**This is for the C Language. Trigonometric Calculator Specification You are required to write a program that calculates and displays values of the trigonometric functions sine, cosine, and tangent for user-supplied angular values. The basic program must comply with the following specification. 1. When the program is run, it is to display a short welcome message. TRIG: the trigonometric calculator 2. The program shall display a message prompting the user to enter input from the keyboard. Please input request (h-help,...
Modify the program in Figure 8.18 so that the following two conditions are met: 1. Each child terminates abnormally after attempting to write to a location in the read-only text segment. 2. The parent prints output that is identical (except for the PIDs) to the following: child 12255 terminated by signal 11: Segmentation fault child 12254 terminated by signal 11: Segmentation fault Modify your solution to Problem 8.24 so that one (and only one) child installs a Segmentation-fault handler which...
5. Write a program that does to perform the following using: Reads a number num that is in the range from 0 to 999999999 and a digit n that is in the range from 0 to 9 from the user. Write while loop to force user to enter appropriate values. . Finds how many times the digit n occurs in the number num. Prints the output as shown. Eİ CAWindowsisystem32cmdexe Enter number ( to 999999999): 3545592 the digit S appears...
this is a C++ program! You will write a program that performs the following tasks for a simple mathematical calculator: (1) Open a user-specified file for input. Prompt for the name of the file, read it into a string variable, echo print it to the terminal and then open it. If the file is not opened, enter into a loop that prints out an error message, resets the input file stream variable (see the hints section), obtains a new file...
Problem Description proving program correctness Consider the following program specification: Input: An integer n > 0 and an array A[0..(n - 1)] of n integers. Output: The smallest index s such that A[s] is the largest value in A[0..(n - 1)]. For example, if n = 9 and A = [ 4, 8, 1, 3, 8, 5, 4, 7, 2 ] (so A[0] = 4, A[1] = 8, etc.), then the program would return 1, since the largest value in...
use python IDEL Please highlight the answer Problem 1 Errors and Exceptions. There are two main types of errors: syntax errors and runtime errors. Syntax errors are detected by the Python interpreter before the program execution during the parsing stage (parsing is a process, during which the Python interpreter analyzes the grammatical structure of the program). Runtime errors are errors in a program that are not detected by the Python interpreter during its parsing stage. They are further divided into...
In python, write the following program, high school question, please keep simple. When I submitted the solution, I get an error as 'wrong answer'. Please note below the question and then the solution with compiler errors. 7.2 Code Practice: Question 2 Instructions Write a program to generate passwords. The program should ask the user for a phrase and number, and then create the password based on our special algorithm. The algorithm to create the password is as follows: If the...