/*Program in c to to find the sum and average of 1D array*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,sum;
float avg=0.0;
printf("Enter the elements of array");
for(i=0;i<5;i++)
scanf("%d" ,&a[i]);
sum=a[0]+a[1]+a[2]+a[3]+a[4];
printf("\n The sum of array is %d " ,sum);
printf("\n The average of array entered is %f ", avg);
getch();
}
Open a computer program like Visual Basic, Java, or C#, and then create an object and label it as an array. Input your 10 numbers into the object, then loop through each object in the array to find the sum, average, and mean by writing code in the program.
In C:
#include <cstdio>
int main()
{
int num, odd, even;
printf("Enter 10 integers: \n");
for(int i = 0; i < 10; i++)
{
scanf("%d", &num);
if(num % 2 0)
{
even++;
}
}
odd = 10 - even;
cout << "Even: " << even << endl;
cout << "Odd: " << odd << endl;
return 0;
}
#include<stdio.h>
int main(){
int i=0,arr[10];
for(i=0;i<5;i++){
scanf("%d",&arr[i]);
}
for(i=0;i<6;i++){
printf("%d \n",arr[i]);
}
printf("\n");
return 0;
}
#include<conio.h>
#include<stdio.h>
void main()
{
float num,avg,sum=0;
int count=1;
clrscr();
printf("Enter ten numbers: \n");
while(count<=10)
{
scanf("%d",&num);
sum+=num;
count++;
}
avg=sum/--count;
printf("\n\nThe sum of the ten numbers = %d",sum);
printf("\nThe average of the ten numbers = %d",avg);
getch();
}
#include
#include
void main()
{
int sum=0,avg=0,a[100],i=0,j=0,k=0;
printf("enter the number of elements wanna add");
scanf("%d",&n);
for(j=0;j<n;j++)
{
k=j+1;
printf("Enter rank %d element element ",k);
scanf("%d",&a[j]);
}
//for sum
for (i=0;i<100;i++)
{
sum=a[i]+sum;
}
printf("sum of nos %d",sum);
for (i=0;i<100;i++)
{
avg=sum/n;
}
printf("avg of nos",avg);
getch();
}
//you can change avg from int to float to get in decimals.
double numbers[10] = { ... };
double sum = 0., mean;
int i;
for (i=0; i<10; i++) sum += numbers[i];
mean = sum / 10.;
#include <stdio.h>
int main (void)
{
int x=3, y=5;
printf ("sum=%d, average=%d\n", x+y, (x+y)/2);
return 0;
}
#include
#include
void main()
{
int i,sum=0;
for(i=1;i<=10;i++)
{
sum=sum+i;
}
printf("%d",sum);
getch();
}
The sum and average of a given number is just that number, so there is no need to write a program.
How to write a program for mouse in microprocessor?
Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.
int array[10] = {...}; for (int i = 0; i < 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }
/* PROGRAM TO SORT ARRAY ELEMENTS USING BUBBLE SORT*/ #include #include void main() { int i,j,n,t,a[50]; clrscr(); printf("ENTER THE ARRAY SIZE:\n"); scanf("%d",&n); printf("ENTER THE ARRAY ELEMENTS:\n"); for(i=0;i
Reference:cprogramming-bd.com/c_page1.aspx# array programming
How to write a program for mouse in microprocessor?
Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.
import java.util.Arrays; public class arraysort { public static void main(String[] a) { int array[] = { 2, 5, -2, 6, -3 }; Arrays.sort(array); for (int i : array) { System.out.println(i); } } }
You cannot delete elements from an array. But you can move the elements: if (del_index < no_of_elements-1) { memmove (&array [del_index], &array [del_index+1], sizeof (array [0]) * (no_of_elements - del_index - 1)); } --no_of_elements;
An aggregate of elements of the same type that occupy contiguous memory.
int array[10] = {...}; for (int i = 0; i < 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }
/* PROGRAM TO SORT ARRAY ELEMENTS USING BUBBLE SORT*/ #include #include void main() { int i,j,n,t,a[50]; clrscr(); printf("ENTER THE ARRAY SIZE:\n"); scanf("%d",&n); printf("ENTER THE ARRAY ELEMENTS:\n"); for(i=0;i
Reference:cprogramming-bd.com/c_page1.aspx# array programming
To write a C++ program to display the student details using class and array of object.
1. write a 'c' program to read 4(four)numbers from a file 'BANK' and calculate the average of the numbers.Now print the calculated average in another output file 'AVERAGE' 2. write a 'c' program that finds the sum and average of inputted five integer numbers of the array using dynamic memory allocation function malloc(). 3. write a 'c' program to create simple elements 1,2,3,4 in the link list of 4(four)nodes and display the list's elements. 4. write a 'c' program to convert the expression (A+B)/(C+D) into postfix expression into stack.and then evaluate it for A=10,B=20,C=15,D=5 and display the stack status after each operation. 5. write a 'c' programto create a linked list implemented on an array containing the following numbers:1,2,3,3,3,4,4,9 and pack it to remove the duplicate numbers.so that only the following data are contained by the nodes:1,2,3,4,9
Create an array with 50 elements and input the integers one a time, filling the array. Use an insertion sort on the array for each input except the first. Alternatively, input the values first and then use insertion sort.
int sumArray(int N, int* A) { int sum = 0; do sum += A[N-1] while (N-- > 1); return sum; }