NITW-PSCP Minor-1 09-09-2019-2-Answers PDF
NITW-PSCP Minor-1 09-09-2019-2-Answers PDF
NITW-PSCP Minor-1 09-09-2019-2-Answers PDF
Note that don’t use arrays for any question, if you write the program using arrays you won’t get any
marks for that.
1 Count of integers in a range, which have even number of odd digits and odd number of even digits.
Given a range [L, R], the task is to count the numbers which have even number of odd digits and odd
number of even digits.
For example:
8 has 1 even digit and 0 odd digit – Satisfies the condition since 1 is odd and 0 is even.
545 has 1 even digit and 2 odd digits – Satisfies the condition since 1 is odd and 2 is even.
4834 has 3 even digits and 1 odd digit – Does not satisfy the condition since there are odd numbers (i.e.
1) of odd digits.
Examples:
Input: L = 1, R = 9, Output: 4
2 ,4 ,6 and 8 are the only integers from the given range that satisfy the given conditions.
Input: L = 1, R = 19, Output: 4
Input: L = 123, R = 984, Output: 431
- Program:
#include<iostream>
using namespace std;
int main(){
int i,l,r,odd,even,no,digit,count;
cout<<"enter range left and right numeric values::";
cin>>l>>r;
if(r<l){
cout<<"wrong range"<<endl;
return 1;
}
count=0;
for(i=l;i<=r;i++){
no=i;
even=0;
odd=0;
while(no>0){
digit=no%10;
if(digit%2==0)
even++;
else
odd++;
no=no/10;
}
if(even%2==1 && odd%2==0)
count++;
}
cout<<"The total number of numbers is::"<<count<<endl;
}
OUTPUT:
int main()
{
for (int i = 1; i<9; i++)
{
for(int j = 0; j<9; j++)
{
for(int k = 0; k<9; k++)
{
for(int l = 0; l<9; l++)
if(i!=j && i!=k && i!=l && j!=k && j!=l && k!=l)
cout<<i<<j<<k<<l<<endl;
}
}
}
return 0;
}
- OUTPUT:
3 According to a study, the approximate level of intelligence of a person can be calculated using the
formula:
i 2 (y 0.5x)
Write a program that will produce a table of values of i, y and x where y varies from 1 to 6, and, for each
value of y, x varies from 5.5 to 12.5 in steps of 0.5.
- Program:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
double i,y,x;
cout<<"i\ty\tx\n";
for(y=1;y<=6;y++)
{for(x=5.5;x<=12.5;x+=0.5)
{i=2+(y+0.5*x);
cout<<i<<"\t"<<y<<"\t"<<x<<endl;
}
}
getch();
return 0;
}
OUTPUT:
4 Our NIT Warangal offer 8 undergraduate programmes. Moreover, let us assume that for each program,
intake of students is 150 based on JEE mains rank. Write a program to read the JEE mains rank of
students in each branch and display the starting rank and ending rank for each branch.
Program:
#include<iostream>
using namespace std;
int main()
{
int sr,er,n,i,j,rank,prgms;
cout<<"Enter the number of undergraduate programmes in NITW\n";
cin>>prgms;
5 As we know, Octal numbers are with base 8. Write a program to display the first n octal numbers.
Example, if the input is 15, the output is: 0,1,2,3,4,5,6,7,10,11,12,13,14,15,16.
- Program:
#include <iostream>
using namespace std;
int main()
{
int n,num,r,q=10,i,flag =0;
cout<<"Enter the no of terms:"<<endl;
cin>>num;
for(i=0; i<=num;i++)
{
n=i;
flag =0;
while (n!=0)
{
r = n%10;
q = n/10;
if( r == 8 || r== 9)
{
num++;
flag=1;
break;
}
n = q;
}
if(flag == 0)
cout<< i <<",";
}
cout<<endl;
return 0;
}
-
OUTPUT: