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

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]
// 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 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....
C# (Thank you in advance) Create an Employee class with five fields: first name, last name,...
C# (Thank you in advance) Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee and SalaryCalculate...
Create a table ‘StudentInfo’ with following fields: ID First Name Last Name SSN Date of Birth...
Create a table ‘StudentInfo’ with following fields: ID First Name Last Name SSN Date of Birth Create a table ‘ClassInfo’ table: ID Class Name Class Description Create a table ‘RegisteredClasses’ table: StudentID ClassID The RegisteredClasses table should have a foreign key relationship to StudentInfo and ClassInfo tables for the respective IDs. Also the IDs in StudentInfo and ClassInfo need to be primary keys. When you submit the file your email should also contain the following SQL Queries: Query to show...
In a Package called characterArray, ********JAVA CODE********** 1) Create a char array containing your full name...
In a Package called characterArray, ********JAVA CODE********** 1) Create a char array containing your full name and print it out. 2) Create an uninitialized char array and copy into it      the char array containing your full name and print it out. 3) Create a Character array and copy into it the char array containing      your full name and print it out. 4) Into the Character array, use toUpperCase() to copy the char array containing     your full name...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT