Professional Documents
Culture Documents
PSCP 18SC1101 Question With Answer Key
PSCP 18SC1101 Question With Answer Key
PSCP 18SC1101 Question With Answer Key
Part-A
1. Arrange the following list of operators according to their precedence from highest to lowest
/,!,>,!=,&&,<=,%,-(unary),++,*,comma operator.
2. void main()
{
int p,q,r;
p=3,q=4,r=0;
r=(p++,q*=p);
}
what are the values of p,q and r after the execution of the above code segment.
Solution: 1 2
21
5.Predict the output of the following bitwise operators a&b, a|b,a^b where a=225,b=196 and
explain.
Solution:
Part-B
Solution:
void main()
{
int i;
for(i=’A’;i<=’Z’;i++)
printf(“%d\t”,i);
}
7.Implement a solution to count number of persons in the age group 50 to 60 by reading read the
age of 100 persons as input using for loop and continue.
Solution:
void main()
{
int i,age,count=0;
for(i=1;i<=100;i++)
{
scanf(“%d”,&age);
if(age>=50 &&age<=60)
count=count+1;
else
continue;
}
printf(“Total number of persons age group 50 to 60 is %d”,count);
}
Solution:
void main()
{
int i,j;
for(i=5;i>0;i--)
{
for(j=1;j<=i;j++)
{
printf(“*”);
}
printf(“\n);
}
}
9.A number is said to be lucky number if it has combination of only digits of 4 and 7 example 4474
is said to be lucky number as it has a combination of 4 and 7,4724 is not said to be a lucky number
and 777,444 are also not lucky numbers. Develop a solution that accepts a positive integer and
check whether it is lucky number or not.
Solution:
#include<stdio.h>
void main()
{
int n,fc=0,sc=0,r,flag=0;
scanf("%d",&n);
while(n>0)
{
r=n%10;
if(r==4)
fc++;
else if(r==7)
sc++;
else
{
flag=1;
break;
}
n=n/10;
}
if (fc>0&&sc>0&&flag==0)
printf("Lucky number");
else
printf("Not a lucky number");
}
Part-C
b) Develop a solution that reads a five digit number aqnd a single digit number and finds
frequencies of single digit number in five digit number.
Solution:
#include<stdio.h>
void main()
{
int fd,sd,r,freq=0;
scanf("%d %d",&fd,&sd);
while(fd>0)
{
r=fd%10;
if(r==sd)
freq++;
fd=fd/10;
}
printf("Total no of frequncy is %d\n",freq);
}
11.a) A number is said to be composite if it has at least one factor other than 1 and itself. This
program prints all the composite numbers starting from 2 to a certain number n, entered by user. We
need to use a nested loop to solve this problem. The outer for loop runs from 2 to n and the inner
loop is used to determine whether a number is composite or not. We need to check for that factors
starting from 2 to integer part of square root of that number.
Solution:
#include<stdio.h>
#include<math.h>
void main()
{
int n,i,j;
scanf("%d",&n);
for(i=2;i<=n;i++)
{
for(j=2;j<= (int)sqrt(i);j++)
{
if(i%j==0)
{
printf("%d\t",i);
break;
}
}
}
}
b) A survey of the computer market shows that personal computers are sold at varying cost by the
vendors. The following is the list of cost (in thousands)
35.00,44.50,25.00,31.25,69.25,46.75,28.15,26.35,56.54,50.62. Develop a solution to determine the
average cost and range of the values.
Solution:
#include<stdio.h>
#include<math.h>
void main()
{
float cost, csum=0.00, max=0.00, min=200000.00, average;
int i;
for(i=1;i<=10;i++)
{
scanf("%f",&cost);
csum=csum+cost;
if(max<cost)
max=cost;
if(min>cost)
min=cost;
}
average=csum/10;
printf("cost average is %.2f\n",average);
printf("Range is in between %.2f to %.2f",min,max);
}