Question

In: Computer Science

Write a program that contains a main method and another method named userName. The main method...

Write a program that contains a main method and another method named userName. The main method should prompt the user to enter a full name. The userName method takes the full name as an argument and prints the name in reverse order and returns the number of characters in the name. See Sample Output (input shown in blue).


Sample Output
Please enter your FULL name
Billy Joe McCallister
Here is the name Billy Joe McCallister in reverse:
retsillaCcM eoJ ylliB
Billy Joe McCallister consists of 21 characters

Solutions

Expert Solution

Code:

#include<stdio.h>
#include<string.h>
int userName(char str[])               //userName() function
   {
   int i,count=0;                   //iterative variable i and count variable to count number of characters
   printf("Here is the name %s in reverse:\n",str);      
   for (i=strlen(str)-1;i>=0;i--)       //iterating loop from last character to starting character by calculating string length .
       {
       printf("%c",str[i]);           //printing each character from the end
       count++;           //incrementing the count it is nothing but counting the number of characters
       }
   printf("\n");
   return count;           //Finally returning the count value
   }
int main()
{
   char str[100];
   printf("Please enter the Full Name\n");           //asking user to enter the full name
   gets(str);                                               //taking input from user
   int num_of_characters=userName(str);               //calling userName() function by passing str paramter and storing num of characters returned by it in variable
   printf("%s consists of %d characters\n",str,num_of_characters);       //printin the number of characters the string consists of
   return 0;
}

Code and Output Screenshots:

Note: if you have any queries please post a comment thanks a lot... always available to help you..


Related Solutions

Write a program named MyHometown_Icon.java. The program will be an application (i.e have a main method)....
Write a program named MyHometown_Icon.java. The program will be an application (i.e have a main method). It will be in the default package. It will import edu.wiu.StdDraw. Its main method will make calls to methods in StdDraw to draw something iconic about your hometown. Multiple colors should be used.Multiple primitive types will be used and the drawing will consists of more than 20 primitive shapes.
Write a program that contains 2 functions. Program will call a function named calc_commission that prompt...
Write a program that contains 2 functions. Program will call a function named calc_commission that prompt the user to enter the sales amount and computes and prints with a description the commission paid to salesperson as follows: 10% for sales amount less than $2,000.00, 15% for sales amount less than $10,000.00 and 20% for sales amount less than $20,000.00, then function calc_commission calls another function name assign_base_salary() to ask the user to enter each of 5 salesperson’s base salary ,...
Write a program that contains the following Write a function copies with two int parameters, named...
Write a program that contains the following Write a function copies with two int parameters, named n and x. It should dynamically allocate a new array of size n.  The function should then copy the value in x to every position in the array. The function should return a pointer to the new array. In the main function, call the copies function from part 1. with size 5 and value -1.  Output the resulting array to the screen, and deallocate the array....
Create a new Python program (you choose the filename) that contains a main function and another...
Create a new Python program (you choose the filename) that contains a main function and another function named change_list. Refer to the SAMPLE OUTPUT after reading the following requirements. In the main function: create an empty list. use a for loop to add 12 random integers, all ranging from 50 to 100, to the list. use second for loop to iterate over the list and display all elements on one line separated by a single space. display the 4th element,...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three integer values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three int||eger values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate....
Part I: Have a program class named TestArrays This class should have a main() method that...
Part I: Have a program class named TestArrays This class should have a main() method that behaves as follows: Have an integer array of size 10. Using a loop, fill the elements with increments of 5, starting with 5 in the first element. Using the array elements, sum the second, fifth and seventh elements. Display the sum with a label. Change the fourth element to 86. Subtract 9 from the ninth element. Using a loop, display the elements of the...
Design a Java program named LambdaTester2 which includes a main method that declares a lambda expression...
Design a Java program named LambdaTester2 which includes a main method that declares a lambda expression reference which implements the following interface: interface Multiplier {     int multiply(int num1, int num2); } The program must declare an array of Pair objects (see class specification below), followed by the declaration of an ArrayList which is instantiated using the declared array (the ArrayList stores Pair objects). Then write a loop which iterates through each element of the ArrayList, calls the lambda expression reference...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT