Question

Write a C program to do the following...in this EXACT order: a. Declare an integer array...

Write a C program to do the following...in this EXACT order:

a. Declare an integer array named alpha of 50 elements.

b. Use a for loopt to initialize each element of alpha to its index value (e.g. alpha[0] = 0, alpha[1]=1, etc.).

c. Output the value of the first element of the array alpha.

d. Output the value of the last element of alpha.

e. Set the value of the 25th element of the array alpha to 62 and output the 25th element.

f. Set the value of element 10 to three times the value of element 50 plus 10 and output element 10.

g. Use a for loop to output the elements of alpha so that there are only 10 elements per line.

h. Use a for loop to output the value of an element of alpha if its index is a multiple of 2 or 3

i. Use a for loop to increment the elements with even numbered indices's;
then output all the elements in the array, 5 elements per line

Here's my code:

#include<stdio.h>

int main(){

int alpha[50];

  

for(int i=0; i<50; i++){

alpha[i]=i;

}

  

printf("The first array element:alpha[0] = %d\n", alpha[0]);

printf("The last array element: alpha[49] = %d\n", alpha[49]);

printf("The 25th array element: alpha[24] = %d\n", alpha[24]);

printf("The 10th array element: alpha[9] = %d\n", alpha[9]);

  

alpha[24]=62;

alpha[10]= (alpha[49]*3)+10;

  

for(int j=0; j<5; j++){

for(int k = j; k <(j+10); k++){

printf("%d",alpha[k]);

  

}

int j= k-1;

printf("\n");

}

  

return(0);

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

void main(){

int alpha[50];
for(int i=0;i<=50;i++){
  
alpha[i]=i;
  
}
printf("Character is %d\n", alpha[0]);
printf("Character is %d\n", alpha[49]);

alpha[24]=62;
printf("Character is %d\n", alpha[24]);

alpha[10]=(3*alpha[49])+10;
printf("Character is %d\n", alpha[10]);

int c=10;

for(int i=0;i<=50;i++){
  
if(i>c){
printf("\n");
c+=10;}
  
printf("%d ", alpha[i]);
  
for(int i=0;i<=50;i++){
if(alpha[i]%2==0 || alpha[i]%3==0)
printf("Character is %d\n", alpha[i]);
}
  
  
for(int i=0;i<=50;i++){
i++;
alpha[i]+=2;
printf("Character is %d\n", alpha[i]);
}
  
}

COMMENT DOWN FOR ANY QUERIES AND,

LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.

Add a comment
Know the answer?
Add Answer to:
Write a C program to do the following...in this EXACT order: a. Declare an integer array...
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
  • C - Language Write a loop that sets each array element to the sum of itself...

    C - Language Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the same. Be careful not to index beyond the last element. Ex: Initial scores: 10, 20, 30, 40 Scores after the loop: 30, 50, 70, 40 The first element is 30 or 10 + 20, the second element is 50 or 20 + 30, and the third element is 70 or 30 +...

  • The following program sorts the array of numbers entered by the user and prints out the...

    The following program sorts the array of numbers entered by the user and prints out the elements in descending order. It has many errors. Debug the code and show the output. #include <stdio.h> #define N 4 void desc(float *a, float *b) float tp; tp=a; a=b; b=tp; int main() int i, j, ii, mark[N] ; for (ii==0;ii<N;ii++) printf("Enter the %d th element of your array: \n",ii); scanf("%d", mark[ii]); printf("You have entered the following array: \n"); for (ii=0,ii<N,ii++) printf("%d ", mark[ii]); printf("\n...

  • Write a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each...

    c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each size Im trying to do time analysis for Quick sort but i keep getting time = 0 also i want edit the program to test different random sizes of the array and give me the time in a...

  • C program-- the output is not right please help me to correct it. #include <stdio.h> int...

    C program-- the output is not right please help me to correct it. #include <stdio.h> int main() { int arr[100]; int i,j,n,p,value,temp; printf("Enter the number of elements in the array: \n "); scanf("%d",&n); printf("Enter %d elements in the array: \n",n); for(i=0;i<n;i++) { printf("\nelement %d: ",i); scanf("\n%d",&arr[i]); } printf("\nEnter the value to be inserted: \n "); scanf("\n%d",&value); printf("The exist array is: \n"); for(i=0;i<n;i++) { printf("%d",arr[i]); } p=i; for(i=0;i<n;i++) if(value<arr[i] ) { p = i; break; } arr[p]=value; printf("\n"); for (i =...

  • JAVA: (15 marks) Write a program that creates an integer array with 50 random values, prompts...

    JAVA: (15 marks) Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. "Out of Bounds") and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle...

  • I need a basic program in C to modify my program with the following instructions: Create...

    I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...

  • How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++...

    How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...

  • Write a C Program that inputs an array of integers from the user along-with the length...

    Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...

  • In need this in C language! Write a program that declares a 40 element array of...

    In need this in C language! Write a program that declares a 40 element array of type double. Initialize the array so that: the first 10 elements are equal to the square of the index variable the next 10 each elements is equal to three times the index variable the next 10 each element is equal to the sum of an element in the first 10 + an element in the second 10 the last 10 each element is equal...

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