0% found this document useful (0 votes)
73 views8 pages

It18111 - Programming For Problem Solving Laboratory EX - NO:5.a Date

The document discusses programming problems involving one and two dimensional arrays. It includes four programming problems and examples involving arrays: 1) Updating array elements to a minimum value such that the new array sum is greater than the original, 2) Counting elements greater than twice an input number, 3) Identifying missing or duplicate numbers in a user-input series, 4) Finding the absolute difference between diagonals of a square matrix. For each problem it provides the question, aim, algorithm, sample program, input/output and result.

Uploaded by

poujhit
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)
73 views8 pages

It18111 - Programming For Problem Solving Laboratory EX - NO:5.a Date

The document discusses programming problems involving one and two dimensional arrays. It includes four programming problems and examples involving arrays: 1) Updating array elements to a minimum value such that the new array sum is greater than the original, 2) Counting elements greater than twice an input number, 3) Identifying missing or duplicate numbers in a user-input series, 4) Finding the absolute difference between diagonals of a square matrix. For each problem it provides the question, aim, algorithm, sample program, input/output and result.

Uploaded by

poujhit
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/ 8

IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO:5.a
DATE:
Simple programming for one dimensional and two dimensional arrays.

QUESTION:
Chandler is assigned a new task today. He is given an array A containing N integers. His task is to
update all elements of array to some minimum value x , that is, A[i]=x, 1<=i<=N ; such that sum of
this new array is strictly greater than the sum of the initial array. Note that x should be as minimum
as possible such that sum of the new array is greater than the sum of the initial array.

Input Format:
First line of input consists of an integer N denoting the number of elements in the array A.
Second line consists of N space separated integers denoting the array elements.
Output Format:
The only line of output consists of the value of x.
Input Constraints:
1 <= N <= 10 power 5
1 <= A[i] <= 1000

AIM:

ALGORITHM:

Roll Number: Page No.:


PROGRAM:
#include<stdio.h>
void main()
{
int a[1000],n,i,s=0,x;
printf("Enter the limit");
scanf("%d",&n);
printf("Enter the values");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
s+=a[i];
}
x=s/n;
printf("Result %d",x+1);
}

SAMPLE INPUT AND OUTPUT:


Enter the limit 6
Enter the values5
6
7
3
9
4
Result 6

RESULT:

IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO:5.b

Roll Number: Page No.:


DATE:
Simple programming for one dimensional and two dimensional arrays.

QUESTION:
Array count is a program that is supposed to return the number of elements in the input array arr
which are greater than twice the input number n. Write a C program to implement the same.

AIM:

ALGORITHM:

PROGRAM:

Roll Number: Page No.:


#include<stdio.h>
void main()
{
int a[20],x,n,i,k=0;
printf("Enter the limit");
scanf("%d",&n);
printf("Enter the values");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the number for comparison");
scanf("%d",&x);
for(i=0;i<n;i++)
if(a[i]>2*x)
k++;
printf("%d",k);
}

SAMPLE INPUT AND OUTPUT:


Enter the limit 6
Enter the values10
15
24
5
9
17
Enter the number for comparison 7
3

RESULT:

IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO:5.c
DATE:
Simple programming for one dimensional and two dimensional arrays.

Roll Number: Page No.:


QUESTION:
User inputs a number and then enters a series of numbers from 1 to N. Determine which number
is missing or duplicated in the series. For example, if the user entered 10as the value of N. The
results should be as shown,
Input sequence Output
1 2 4 7 4 4 5 10 8 2 6 Duplicate 2
Missing 3
Duplicate 4
Missing 9
AIM:

ALGORITHM:

PROGRAM:
#include<stdio.h>
void main()
{

Roll Number: Page No.:


int a[20],b[20]={0},i,n;
printf("Enter the limit");
scanf("%d",&n);
printf("Enter the values");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
b[(a[i]-1)]++;
for(i=0;i<n;i++)
if(b[i]==0)
printf("Missing:%d\n",i+1);
else if(b[i]>1)
printf("Repeated:%d\n",i+1);
}

SAMPLE INPUT AND OUTPUT:


Enter the limit 10
Enter the values 3
2
4
5
3
4
9
7
1
7
Repeated :3
Repeated:4
Missing :6
Repeated:7
Missing :8
Missing: 10

RESULT:

IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO:5.d
DATE:
Simple programming for one dimensional and two dimensional arrays.

QUESTION:
The teacher of a class decided to make a game for the students to find the fast computing person
in the class. The game was to find the diagonal difference of the matrix and shout the absolute

Roll Number: Page No.:


value of the same. The condition is that it should always be a square matrix. Write a C-program for
the same.

AIM:

ALGORITHM:

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
void main()
{
int a[10][10],m,n,i,j,x=0,y=0;
printf("Enter the dimensions");
scanf("%d%d",&m,&n);

Roll Number: Page No.:


if(m==n)
{
printf("Enter the values");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(i=0,j=n-1;i<m;i++,j--)
{
x+=a[i][i];
y+=a[i][j];
}
printf("Result is %d",abs(x)-abs(y));
}
}

SAMPLE INPUT AND OUTPUT:


Enter the dimensions3
3
Enter the values1
6
3
7
-4
2
-5
9
8
Result is -1

RESULT:

Roll Number: Page No.:

You might also like