0% found this document useful (0 votes)
39 views5 pages

Assignment 6: Programs With Arrays

The document contains an assignment to write 4 programs using arrays: 1) To find the sum of 20 numbers in an array 2) To find the minimum and maximum numbers in an array 3) To find numbers in an array divisible by a given number 4) To shift all numbers in an array one position to the right For each program, the student provided the code to solve the problem.

Uploaded by

abhinav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views5 pages

Assignment 6: Programs With Arrays

The document contains an assignment to write 4 programs using arrays: 1) To find the sum of 20 numbers in an array 2) To find the minimum and maximum numbers in an array 3) To find numbers in an array divisible by a given number 4) To shift all numbers in an array one position to the right For each program, the student provided the code to solve the problem.

Uploaded by

abhinav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT 6

PROGRAMS WITH ARRAYS

1. Write a program to find sum of twenty numbers using


arrays.
2. Write a program to find minimum and maximum number in
an array.
3. Write a program to find numbers in an array that are
divisible by a given number.
4. Write a program to shift numbers right in an array.

HARSHIT GUPTA (XI A7)


1. //Write a program to find sum of twenty numbers using arrays

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>

void main()
{
clrscr();
int i,num[20],sum=0;
cout<<"Enter 20 numbers \n";
for(i=0;i<20; ++i)
{
cin>>num[i];
sum+=num[i];
}
cout<<"the sum of the numbers is "<<sum;
getch();
}

HARSHIT GUPTA (XI A7)


2. //Write a program to find minimum and maximum number in an array

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>

void main()
{
clrscr();
int n, num[50], max=0;
cout <<"How many numbers you want to enter? \n" ;
cin>>n;
cout<<"enter the numbers \n";
for(int i=0;i<n;++i)
{
cin>>num[i];
if(max<num[i])
max=num[i];
}
int min=num[0];
for(i=0;i<n;++i)
{
if(min>num[i])
min=num[i];
}
cout<<"the minimum number is "<<min;
cout<<"\n the maximum number is "<<max;
getch();
}

HARSHIT GUPTA (XI A7)


3. //Write a program to find numbers in an array
//that are divisible by a given number

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>

void main()
{
clrscr();
int n=0, i=0, num[50], x=0;
cout <<"How many numbers you want to enter? \n" ;
cin>>n;
cout<<"enter the numbers \n";
for(i=0;i<n;++i)
cin>>num[i];
cout<<"enter the number to check for divisibility \n";
cin>>x;
cout<<"the numbers divisible by "<<x<<" are \n";
for(i=0;i<n;++i)
if(num[i]%x==0)
cout<<num[i]<<" ";
getch();
}

HARSHIT GUPTA (XI A7)


4. //Write a program to shift numbers right in an array
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>

void main()
{
clrscr();
int n=0, i=0, num[50], x=0;
cout <<"How many numbers you want to enter? \n" ;
cin>>n;
cout<<"enter the numbers \n";
for(i=0;i<n;++i)
cin>>num[i];
x=num[i--];
for(;i>0 ;i--)
num[i]=num[i-1];
num[0]=x;
cout<<"the modified array is \n";
for(i=0;i<n;i++)
cout<<num[i]<<" ";
getch();
}

HARSHIT GUPTA (XI A7)

You might also like