Hello, I need help for this assignment is about loops and arrays by using C# lan
ID: 3930469 • Letter: H
Question
Hello, I need help for this assignment is about loops and arrays by using C# language.
1. Create an array of 50 random integers. Then loop through the array and output a count of how many of the array elements are even numbers;
2. Create an array of strings. Place about 10 of your favorite quotes in the array. Use a random number generator to randomly select and display one of the quotes from the array every time you run the program.
3. Create an array of 10 doubles. Prompt a user to enter numbers into the array. After all the numbers have been entered display all the numbers in the array, the total of the numbers and the average.
Thank you
Explanation / Answer
1)solution
#include<stdio.h>
#include<stdlib.h>
int main(){
int array[50];
int i,element;
int count=0;
for(i=0;i<50;i++)
{
array[i]=rand() % 100;
}
for(element=1;element<=50;element++)
{
if(array[element]%2==0)
count++;
printf("Element[%d] = %d ", element, array[element] );
}
printf("the no of even numbers are %d",count);
}
output
Element[1] = 67
Element[2] = 34
Element[3] = 0
Element[4] = 69
Element[5] = 24
Element[6] = 78
Element[7] = 58
Element[8] = 62
Element[9] = 64
Element[10] = 5
Element[11] = 45
Element[12] = 81
Element[13] = 27
Element[14] = 61
Element[15] = 91
Element[16] = 95
Element[17] = 42
Element[18] = 27
Element[19] = 36
Element[20] = 91
Element[21] = 4
Element[22] = 2
Element[23] = 53
Element[24] = 92
Element[25] = 82
Element[26] = 21
Element[27] = 16
Element[28] = 18
Element[29] = 95
Element[30] = 47
Element[31] = 26
Element[32] = 71
Element[33] = 38
Element[34] = 69
Element[35] = 12
Element[36] = 67
Element[37] = 99
Element[38] = 35
Element[39] = 94
Element[40] = 3
Element[41] = 11
Element[42] = 22
Element[43] = 33
Element[44] = 73
Element[45] = 64
Element[46] = 41
Element[47] = 11
Element[48] = 53
Element[49] = 68
Element[50] = 35
the no of even numbers are 22
3)solution
#include<stdio.h>
#include<stdlib.h>
int main(){
//to intialize the variables
double array[10];
int i,element;
int count=0;
int size;
printf("Enter the 10 double data types elements to insert in array ");
//scanf("%d", &size);
//printf("Enter %d elements ", size);//to give the size
//for (i = 0; i < size; i++)//to insert any no of elements dynamically
for(i=0;i<10;i++)
scanf("%lf", &array[i]);
for(element=0;element<10;element++)
{
printf("the element[%f] is %.1f ", element, array[element] );//to print the array
count++;
}
printf("the total no of elements are %d",count);
}
output
Enter the 10 double data types elements to insert in array
1.2
3.2
4.3
6.5
5.3
9.5
8.6
4.5
6.3
8.9
the element[0.000000] is 1.2
the element[0.000000] is 3.2
the element[0.000000] is 4.3
the element[0.000000] is 6.5
the element[0.000000] is 5.3
the element[0.000000] is 9.5
the element[0.000000] is 8.6
the element[0.000000] is 4.5
the element[0.000000] is 6.3
the element[0.000000] is 8.9
the total no of elements are 10
2)solution
#include<stdio.h>
#include<stdlib.h>
int main(){
int k;
char *string[10]={"flowers", "fruits", "colors", "festivals","traditions","festivals","competitions","races","bettings","values"};
for(k=0;k<=10;k++){
printf("%s ",string[k]);
}
int i=rand()%10;
printf("the random generate quote no is %d ",i);
for(k=0;k<=10;k++){
if(k==i)
{
printf("the matching string randomly is %s ",string[k]);
}
}
return 0;
}
output
flowers
fruits
colors
festivals
traditions
festivals
competitions
races
bettings
values
the random generate quote no is 1
the matching string randomly is fruits
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.