c programs using Array
1.write a c program to ftnd the average of 10 random numbers
1.write a c program to ftnd the average of 10 random numbers
#include
<stdio.h>
main()
{
int n, t;
float num[100], sum = 0, avg;
printf("Enter the numbers of elements:
");
scanf("%d", &n);
printf("Enter the number: ");
scanf("%d", &n);
}
for (t = 0; t < n; t++)
{
printf("Enter number: ");
scanf("%f", &num[t]);
sum += num[t];
}
avg = sum / n;
printf("Average = %f", avg);
}
Outtut
Enter the
numbers of elements: 6
1. Enter
number: 45.3
2. Enter
number: 67.5
3. Enter
number: -45.6
4. Enter
number: 20.34
5. Enter
number: 33
6. Enter
number: 45.6
Average =
27.69
2.write a c Program to find the Largest number from a random 10 numbers
#include
<stdio.h>
main()
{
int t, n;
float a[100];
printf("Enter any number: ");
scanf("%d", &n);
for (t = 0; t < n; ++t)
{
printf("Enter number");
scanf("%f", &a[t]);
}
// storing the largest number to a[0]
for (t = 1; t < n; t++)
{
for (a[0] < a[t])
a[0] = a[t];
}
printf("Largest element = %f",
a[0]);
}
Outtut
Enter the
number : 5
Enter
number1: 34.5
Enter
number2: 2.4
Enter
number3: -35.5
Enter
number4: 38.7
Enter
number5: 24.5
Largest
element = 38.70
Comments
Post a Comment