Answer to Question #250733 in C for Hazzy

Question #250733

Exercise 1: Practice to store and print data in an array

 a) Write a C program that reads marks of 10 students in to a single subscripted array.

 b) Above marks should be between 0 to 20. Modify the above program to add marks to the array only if the input mark is between the given range.

 c) Display the values stored in the array.


 Exercise 2: Practice to access data stored in an array

 Modify the above program to find the mean of the marks stored in the array.


 Exercise 3: Practice to manipulate data in arrays 

Write a C program to create an integer array called Motion of size 5. Ask the user to enter values to the array from the keyboard. Rotate the values of the array by one position in the forward direction and display the values.

 Ex: number in index 4 should move to index 3, Number in index 3 should move to index2, number index 0 should move to index 4. 

Initial values 10 6 8 2 9

 After rotating 6 8 2 9 10 


 


1
Expert's answer
2021-10-13T06:25:06-0400
 Exercise 1

#include<stdio.h>


int main(){
	int marks[10];
	int m;
	int i;
	int n=0;
	for(i=0; i<10; i++){
		printf("Enter mark %d: ",(i+1));
		scanf("%d", &m);
		if(m>0 && m<20){	
			marks[n]=m;
			n++;
		}
	}
	
	printf("All marks in the range of 0 and 20 are:\n");
	for(i=0; i<n; i++){
		printf("%d ", marks[i]);
	}


	getchar();
	getchar();


	return 0;
}



 Exercise 2

#include<stdio.h>


int main(){
	int marks[10];
	int m;
	int i;
	int n=0;
	double mean;
	double sum=0;
	for(i=0; i<10; i++){
		printf("Enter mark %d: ",(i+1));
		scanf("%d", &m);
		if(m>0 && m<20){	
			marks[n]=m;
			sum+=m;
			n++;
		}
	}
	
	printf("All marks in the range of 0 and 20 are:\n");
	for(i=0; i<n; i++){
		printf("%d ", marks[i]);
	}
	mean=sum/n;
	printf("\n\nThe mean of the marks stored in the array: %.2f\n",mean);


	getchar();
	getchar();


	return 0;
}




Exercise 3

#include<stdio.h>
int main() {
	int Motion[5];
	int i;
	int tempValue;
	for(i=0;i<5;++i){
		printf("Enter the value %d: ",(i+1));
		scanf("%d",&Motion[i]);
	}
	printf("Original array:\n");
	for( i=0;i<5;++i){
		printf("%d ",Motion[i]);
	}
	tempValue = Motion[0];
	for ( i = 0; i < 4; i++){
	    Motion[i] = Motion[i + 1];
	}
    Motion[4] = tempValue;
	printf("\n\nArray after rotation by one position in the forward direction:\n");
	for(i=0;i<5;++i){
		printf("%d ",Motion[i]);
	}
	getchar();
	getchar();
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS