You are on page 1of 5

KLEF, Guntur

FED: Basic Engineering Science - I


A Y: 2018-2019(Odd semester)

18SC1101-Problem solving and computer Programming

Date of Semester-In Examination-I : 11.09.2018 (50 marks)

Questions and Answer Key

Part-A

1. Arrange the following list of operators according to their precedence from highest to lowest
/,!,>,!=,&&,<=,%,-(unary),++,*,comma operator.

Solution: ++,-(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: p=4,q=16, r=16

3. Identify the output of the following code snippet.


void main()
{
int a,b,c;
a=025;
b=072;
c=a+b;
printf(“%d”,c);
c=b-a;
printf(“%d”,c);
}
Solution: 79 37

4.Predict the output of the following code snippet.


main()
{
int i,j;
for(i=1;i<=2;i++
{
for(j=1;j<=2;j++)
{
if(i==j)
continue;
printf(“\n%d %d\n”,i,j;
}
}
}

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:

A=225,b=196 a&b a|b a^b


a=11100001&b= 11000100 11000000=192 11100101=229 00100101=37

Part-B

6. Develop a solution to print ASCII values of all character.(A=65,B=66,...Z=90).

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);
}

8. Print inverted half pyramid through c Program


*****
****
***
**
*

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

10.a) Develop a solution that does the following :


It accepts a sequence of integer from the user ,continuing as long as the user enters even integer.
Once an odd integer is entered ,the program stops accepting input. The program then computes the
total number of even integer entered, the sm of them and print those out.
Solution:
#include<stdio.h>
void main()
{
int n,evencount=0,evensum=0;
while(1)
{
scanf("%d",&n);
if(n%2==0)
{
evencount++;
evensum=evensum+n;
}
else
break;
}
printf("Total no of even no is %d\n",evencount);
printf("Even sum=%d",evensum);
}

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);
}

*** Best of Luck ***

You might also like