Page Contents
Interview Content
- C Programming Coding Questions
- C Pattern Programming Questions
- C Programming Interview Questions
- Java Programming Coding Questions
- Java Pattern Programming Questions
- Java Programming Interview Questions
- Python Programming Coding Questions
- Python Pattern Programming Questions
- Python Programming Interview Questions
- SQL Interview Questions
Python Program to find missing number in array
Ans:
In this tutorial, you will learn writing a program using Python to find the missing number in integer array of 1 to 100.
This Program is not generic, It has some limitations like
- It can find only one missing number in an array.
- Here we are just adding numbers from 0 to n, where n is number of elements array can have.
- User can give input only between 0 to n.
- To find missing number, subtract sum of numbers given by user from total sum of numbers from 0 to n.
Also Read This: Java Program to find missing number in array.
Python Program to find missing number in array
arr = []
n = int(input("enter size of array : "))
for x in range(n-1):
x=int(input("enter element of array : "))
arr.append(x)
sum = (n*(n+1))/2;
sumArr = 0
for i in range(n-1):
sumArr = sumArr+arr[i];
print(int(sum-sumArr))
Output:
Also prepare these Python Programs:
- Write a program to reverse an integer in Python.
- Write a program in Python to check whether an integer is Armstrong number or not.
- Python Program to check a given number is Prime number or not.
- Write a program in Python to print the Fibonacci series using iterative method.
- Write a program in Python to print the Fibonacci series using recursive method.
Latest Uploads on Website
- AVL Tree with explanation
- Radix sort algorithm explanation with example
- Quick Sort Algorithm with explanation
- Bubble sorting algorithm with Bubble sort program in C
- Insertion sort algorithm and program in C
- Selection Sort Algorithm and Program in C
- Linear probing technique explanation with example
- Collision in Hashing and Collision resolution technique
- Hashing in data structure with its types
- Binary search tree operations with Program
- Binary search tree in data structure
- Binary search algorithm in data structure with explanation
- linear search in data structure with Algo and Program