0% found this document useful (0 votes)
19 views

Y Y Y YY Y Y YY Y Y Yy !"yy Y Y !Y"Yy Y##Y Y Yy"Yy Y $Y Y Y !"yy ##Y Y Y%Y&Yy "Y Y ##Y # Y 'Y Y"Yy (Y $Y

The document discusses three C++ programs: 1. A program to find the sum of elements in an array by inputting elements, displaying them, and calculating the sum. 2. A program to reverse the order of elements in an array by inputting elements, displaying them in original and reverse order. 3. A program to input 10 integers into an array, sort them in ascending order using a bubble sort algorithm, and display the sorted array.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Y Y Y YY Y Y YY Y Y Yy !"yy Y Y !Y"Yy Y##Y Y Yy"Yy Y $Y Y Y !"yy ##Y Y Y%Y&Yy "Y Y ##Y # Y 'Y Y"Yy (Y $Y

The document discusses three C++ programs: 1. A program to find the sum of elements in an array by inputting elements, displaying them, and calculating the sum. 2. A program to reverse the order of elements in an array by inputting elements, displaying them in original and reverse order. 3. A program to input 10 integers into an array, sort them in ascending order using a bubble sort algorithm, and display the sorted array.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Program to find the sum of elements of array

#include<iostream.h> #include<conio.h> void main() { clrscr(); int ar[10],n,s=0; cout<<"Enter size of the array: "; cin>>n; cout<<"Enter array element: "<<endl; for(int i=0;i<n;i++) { cout<<"Enter element "<<i<<": "; cin>>ar[i]; } cout<<"Elements of array: "<<endl; for(i=0;i<n;i++) cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl; for(i=0;i<n;i++) s=s+ar[i]; cout<<"Sum of elements: "<<s; getch(); }

SCREEN Enter size of the array: 4 Enter array element: Enter element 0: 3 Enter element 1: 4 Enter element 2: 5 Enter element 3: 2 Elements of array: Element at index number 0 is: 3 Element at index number 1 is: 4 Element at index number 2 is: 5 Element at index number 3 is: 2 Sum of elements: 14

Write a program to reverse elements of array


#include<iostream.h> #include<conio.h> void main() { clrscr(); int ar[10],n,s=0; cout<<"Enter size of the array: "; cin>>n; cout<<"Enter array element: "<<endl; for(int i=0;i<n;i++) { cout<<"Enter element "<<i<<": "; cin>>ar[i]; } cout<<"Elements of array in original order: "<<endl; for(i=0;i<n;i++) cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl; cout<<"Elements of array in reverse order: "<<endl; for(i=n-1;i>=0;i--) cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl; getch(); }

Input Enter size of the array: 6 Enter array element: Enter element 0: 3 Enter element 1: 4 Enter element 2: 5 Enter element 3: 7 Enter element 4: 5 Enter element 5: 8 Output Elements of array in original order: Element at index number 0 is: 3 Element at index number 1 is: 4 Element at index number 2 is: 5 Element at index number 3 is: 7 Element at index number 4 is: 5 Element at index number 5 is: 8 Elements of array in reverse order: Element at index number 5 is: 8 Element at index number 4 is: 5 Element at index number 3 is: 7 Element at index number 2 is: 5 Element at index number 1 is: 4 Element at index number 0 is: 3

Program to enter 10 integers in a single-dimension array and then print out the array in ascending order
#include <iostream.h> #include <conio.h> void main() { clrscr(); int array[10],t; for(int x=0;x<10;x++) { cout << "Enter Integer No. " << x+1 << " : " << endl; cin>>array[x]; } for (x=0;x<10;x++) { for(int y=0;y<9;y++) { if(array[y]>array[y+1]) { t=array[y]; array[y]=array[y+1]; array[y+1]=t; } } } cout << "Array in ascending order is : "; for (x=0;x<10;x++) cout << endl << array[x]; getch(); }

INPUT
43 67 53 21 6 78 92 48 95 8

OUTPUT
Array in ascending order is : 6 8 21 43 48 53 67 78 92 95

You might also like