You are on page 1of 7

Programming Questions

Easy Questions

1. Python program to convert Fahrenheit into Celsius

#taking input from the user


fahrenheit = float(input(“Please give the Fahrenheit Temperature : “))
#converting Celsius into Fahrenheit
celsius = ((fahrenheit-32)*5)/9
print(“Celcius= “,celsius)

2. Write a program in C++ to print the sum of two numbers.

#include <iostream>
using namespace std;

int main()
{
cout << "\n\n Print the sum of two numbers :\n";
cout << "-----------------------------------\n";
int a;
int b;
int sum;
a=29;
b=30;
sum=a+b;
cout << " The sum of "<< a << " and "<<b <<" is : "<< sum <<"\n\n" ;
}
3. Write a program in C++ to swap two numbers

#include <iostream>
using namespace std;

int main()
{
cout << "\n\n Swap two numbers :\n";
cout << "-----------------------\n";
int num1, num2, temp;
cout << " Input 1st number : ";
cin >> num1 ;
cout << " Input 2nd number : ";
cin >> num2;
temp=num2;
num2=num1;
num1=temp;
cout << " After swapping the 1st number is : "<< num1 <<"\n" ;
cout << " After swapping the 2nd number is : "<< num2 <<"\n\n" ;
}

4. Python program to find L.C.M. of two numbers

num1 = int(input(“Enter first number: “))


num2 = int(input(“Enter second number: “))
if num1 > num2:
  greater = num1
else:
  greater = num2
while(True):
  if((greater % num1 == 0) and (greater % num2 == 0)):
      lcm = greater
      break
  greater += 1
print(“LCM of”,num1,”and”,num2,”=”,greater)
5. Write a program in C++ that converts kilometers per hour to miles per hour.

#include <iostream>
using namespace std;

int main()
{
float kmph, miph;
cout << "\n\n Convert kilometers per hour to miles per hour :\n";
cout << "----------------------------------------------------\n";
cout << " Input the distance in kilometer : ";
cin >> kmph;
miph = (kmph * 0.6213712);
cout << " The "<< kmph <<" Km./hr. means "<< miph << " Miles/hr." <<
endl;
cout << endl;
return 0;
}

Average Questions

1. In Python, in what ways can you make an empty NumPy array?

import numpy  
#method 1  
array_1 = numpy.array([])  
print(array_1)  

#method 2  
array_2 = numpy.empty(shape=(3,3))  
print(array_2)  
2. Using Python/ NumPy, write code to compute percentiles?

import numpy   
array = numpy.array([3, 6, 1, 6, 5, 2])  
percentile = numpy.percentile(array, 45) #Returns 45th percentile  
print(percentile) 

3. Using the data set, convert the data set to the csv and count the total cars in the company

import pandas as pd
df = pd.read_csv("D:\\Python\\Articles\\pandas\\automobile-
dataset\\Automobile_data.csv")
df['company'].value_counts()

4. Python code for displaying Fibonacci series up to 10 terms

# first two numbers


num1, num2 = 0, 1

print("Fibonacci sequence:")
# run loop 10 times
for i in range(10):
# print next number of a series
print(num1, end=" ")
# add last two numbers to get next number
res = num1 + num2

# update values
num1 = num2
num2 = res
5. Jim currently runs a car rental dealership and wishes to write a program that allows the user to
enter the temperature of the location they plan to visit and then recommend a car based on the
data. Below is a summary of the program structure Jim is looking for. Temp greater than 80
a Convertible should be selected. Temp greater than 60 and less than 80 an SUV should be
selected Temp less than 60 a truck should be selected. Jim has no trouble writing the code
if the temperate is greater than 80 but gets stuck when he arrives at the second line of code
which reads Temp greater than 60 and less than 80 an SUV should be selected. What type of
operator is Jim needing to use within his code?

A. &&

B. | |

C. !=

D. ==

Answer: A
Difficult Questions:

1. Find Grade of Student based on Marks obtained in all Subjects using user-
defined Function. Here user is allowed to enter number of subject

The grade must be calculated based on following pattern:

#include<iostream>
using namespace std;
int main()
{
int i;
float mark, sum=0, avg;
cout<<"Enter Marks obtained in 5 Subjects: ";
for(i=0; i<5; i++)
2. Find Arithmetic Mean using user-defined Function

#include<iostream>
using namespace std;
int main()
{
int n, i;
float arr[50], sum=0, armean;
cout<<"How many number, You want to enter ?
";
cin>>n;
cout<<"\nEnter "<<n<<" Number: ";
for(i=0; i<n; i++)
{
cin>>arr[i];
sum = sum+arr[i];
}
armean = sum/n;
cout<<"\nArithmetic Mean = "<<armean;
cout<<endl;
return 0;
}

You might also like