Question

In: Computer Science

Part 1: Create a character array and save your first and last name in it

PROGRAMMING IN C:

Part 1:

Create a character array and save your first and last name in it

Note: You can assign the name directly or you can use the scanf function.

  1. Display your name on the screen.

  2. Display the address (memory location) in hexadecimal notation of the array. (hint: use %p)

  3. Use a for loop to display each letter of your name on a separate line.

Part 2:

Create a one dimensional array and initialize it with 10 integers of your choice.

Create a function and pass the array elements to that function. The function will calculate the average value of the 10 integers and display the result on the screen.

Part 3:

Create a one dimensional array that contains five integers (10, 20, 30, 40 and 50).

Display the elements of the array on screen

Swap the first element (10) with the last element (50) and then display the elements of the array on the screen (after swapping).

Solutions

Expert Solution

Part 1:

Output:

Code:

#include


int main()
{
char arr[]={"John Peter"};

printf("Name : %s",arr);

printf("\n");

printf("Address : %p",&arr);

int length=sizeof(arr)/sizeof(arr[0]);

printf("\n");

int i;
for(i=0;i {
    printf("%c",arr[i]);
    printf("\n");
}
   
}

*********************************************************************************************************************

Part 2:

Output:

Code:

#include

void func(int arr[],int length)
{
   int sum=0;
  
   int i;
   for(i=0;i    {
       sum=sum+arr[i];
   }
  
   float average=(float)sum/length;
  
   printf("Average : %f",average);
}

int main()
{
int arr[]={10,25,36,52,15,34,89,12,56,69};

func(arr,10);
}

****************************************************************************************************************************

Part 3:

Output:

Code:

#include

int main()
{
int arr[]={10,20,30,40,50};

printf("\nBefore Swapping :\n\n");

int i;

for(i=0;i<5;i++)
{
    printf("%d ",arr[i]);
}

int temp=arr[0];
arr[0]=arr[4];
arr[4]=temp;

printf("\n\nAfter Swapping : \n\n");

for(i=0;i<5;i++)
{
    printf("%d ",arr[i]);
}
}


Related Solutions

JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
Please consider FIRST 6 Character from your name and LAST 2 digits of your students ID....
Please consider FIRST 6 Character from your name and LAST 2 digits of your students ID. Calculate the checksum for the above text. The text needs to be divided into 2-byte (16-bit) words. Also check that the data is reached without any alteration using your checksum. [ the text is MajedA08]
In C, 1) Create variables for: your first and last name total round trip to school...
In C, 1) Create variables for: your first and last name total round trip to school and home (assuming you don't live on campus - make it your hometown). cost of gas 2) Create a program that will: output your first name and your total miles driven for the week. output your last name with the total costs per week
// This program performs a linear search on a character array // Place Your Name Here...
// This program performs a linear search on a character array // Place Your Name Here #include<iostream> using namespace std; int searchList( char[], int, char); // function prototype const int SIZE = 8; int main() { char word[SIZE] = "Harpoon"; int found; char ch; cout << "Enter a letter to search for:" << endl; cin >> ch; found = searchList(word, SIZE, ch); if (found == -1) cout << "The letter " << ch      << " was not found in...
***IN C++*** Create student structure with the following fields:  Name (cstring or null-terminated character array)...
***IN C++*** Create student structure with the following fields:  Name (cstring or null-terminated character array)  Student ID (int – unique random value between 1000 and 9999)  grade (char – Values A thru F)  birthday (myDate – random value: range 1/1/2000 to 12/31/2005)  Home Town (string) Create an array of pointers to students of size 10. Example: Student *stuPtr[10]; Write a function that populates the array with 10 students. Example: populate(stuPtr); Write a display function that...
1. Create a PHP program containing an multi dimensional array of all the first and last...
1. Create a PHP program containing an multi dimensional array of all the first and last names of the students in your class. Sort the array by last name in alphabetic order. Also sort the array in reverse order. 2. Split the array from #1 into two arrays; one containing first names, the other containing last names.
Create a table with two columns. Name the table First Initial _ Last Name (e.g. John...
Create a table with two columns. Name the table First Initial _ Last Name (e.g. John Dow will create table j_dow). You have to audit all DML statements on your table. To do this you write two triggers: 1. To log any DML statements that users might run on this table. The results must be stored in the First Initial _ Last Name _ Log table (e.g. John Dow will create table j_dow_log). The table should have unique event ID,...
C Write a function that appends the second character array to the first, replaces the first...
C Write a function that appends the second character array to the first, replaces the first array with the result and replaces the second character array with the original first array. For example, if the first character array is "hello" and the second is "world" at the end of the function the new value of the first character array should be"helloworld" and the second array should be "hello". If the input is invalid the function should return 1. Otherwise, the...
Create a class Employee. Your Employee class should include the following attributes: First name (string) Last...
Create a class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyEmployee that inherits from the Employee class.   HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the...
Create the following SQL queries using the lyrics database below 1. List the first name, last...
Create the following SQL queries using the lyrics database below 1. List the first name, last name, and region of members who do not have an email. 2. List the first name, last name, and region of members who do not have an email and they either have a homephone ending with a 2 or a 3. 3. List the number of track titles that begin with the letter 's' and the average length of these tracks in seconds 4....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT