You are on page 1of 10

COMPUTATIONAL THINKING FOR STRUCTURED DESIGN

1. Anuj takes a loan of Rs.7,00,000 to pay his B.Tech fees from his friend at 12.5% rate of interest. He needs to clear the dues to get th
Objection Certificate. Help him in finding out the amount to be paid with interest to the bank. Interest is computed using Simple Interest
period of 4 Years. Pass inputs as parameters to a function name Simple_Interest which will return the interest to the main function.

#include <stdio.h>
int simint(int p, int t, int r);
int simint(int p, int t, int r)
{
int si= (p*t*r)/100;
return si;
}

int main()
{
int p,r,t,si;
printf("enter p,t,r:");
scanf("%d %d %d", &p,&t,&r);
si=simint(p,t,r);
printf("SI:%d",si);
}

2. Mr. Ravi has prepared a test-1 question paper for 1st year B. Tech. The test consists of 3 questions with each question
having certain marks assigned to it. However, Mr. Ravi has assigned distinct marks for each of 3 questions. This means no two
questions can have the same marks. Find the minimum and maximum marks that he set the paper for. Solve this
problem using arrays by declaring the array globally.

#include <stdio.h>
int min(int a[]);
int max(int a[]);
int min(int a[])
{
int min=a[0];
min=a[1]<min?a[1]:min;
min=a[2]<min?a[2]:min;
printf("min:%d\n",min);
}
int max(int a[])
{
int max=a[0];
max=a[1]>max?a[1]:max;
max=a[2]>max?a[2]:max;
printf("max:%d\n",max);
}
int main()
{
int a[3]={10,12,5};
min(a);
max(a);

3. Six friends go on a trip and are looking for accommodation. After looking for hours, they find a hotel which offers two types of rooms — do
rooms and triple rooms. A double room costs Rs. X, while a triple room costs Rs. Y. The friends can either get three double rooms or get two
rooms. Find the minimum amount they will have to pay to accommodate all six of them.

Page 1 of 10
COMPUTATIONAL THINKING FOR STRUCTURED DESIGN

#include <stdio.h>
int rooms(int x,int y);
int rooms(int x, int y)
{
int sum,tot;
sum=x*3;
tot=y*2;
if(sum>tot)
printf("%d\n",tot);
else
printf("%d\n",sum);
}
int main()
{
int x,y;
printf("Enter x,y values:");
scanf("%d %d",&x,&y);
rooms(x,y);
return 0;
}

4. Manisha works in a supermarket in billing. A customer bought 10 pens and 5 chocolates. Each pen costs Rs. 1.5 and each chocolate cost
10. By using functions help Manisha to calculate the total bill amount and remaining change to be returned if the customer
Rs. 100.
#include <stdio.h>
int bill(int c,int p,int cc,int cp);
int bill(int c,int p,int cc,int cp)
{
int tot;
tot=c*cc+p*cp;
printf("total bill:%d",tot);

}
int main()
{
int c,p,cc,cp;
printf("Enter c,p,cc,cp values:");
scanf("%d %d %d %d",&c,&p,&cc,&cp);
bill(c,p,cc,cp);
return 0;
}

5. Kavya has seen one brochure and observed some mobile numbers on it. Suddenly she focuses on extreme two digits and she want to find
of first 2 digits and last 2 digits. Can you please help Kavya for finding sum by passing the array as a parameter to the function?

#include <stdio.h>
long long int digit(int ph);
long long int digit(int ph)
{
int n1,n2,sum;
n1=ph%100;
n2=ph/100000000;
sum=n1+n2;
printf("n1:%d n2:%d\n",n1,n2);
printf("sum:%d",sum);
}

Page 2 of 10
COMPUTATIONAL THINKING FOR STRUCTURED DESIGN

int main()
{
long long int ph;
printf("Enter ph:");
scanf("%lld",&ph);
digit(ph);
}

6. Raghu found a new Instagram page related to problem solving, in that page they will upload some logical questions related to datatypes. o
the question he finds is Read an array of characters and print the array using pointer, by passing the array as function parameter. Raghu is we
pointers and funtions. Can you please help Raghu to find solution?

#include <stdio.h>
char printchar(char *ptr);
char printchar(char *ptr)
{
printf("%c %c %c %c %c",*ptr,*(ptr+1),*(ptr+2),*(ptr+3),*(ptr+4));
}
int main()
{
char a[10];
printf("Enter 5 array char:");
scanf("%c %c %c %c %c",&a[0],&a[1],&a[2],&a[3],&a[4]);
printchar(a);
}
7.a. Predict the output for the following code:
#include<stdio.h>
void f() {
int a;
a=20;
d();
printf("%d",a);
}
void d() {
int a;
a=30;
printf("%d",a);
}
int main() {
int a;
a = 10;
printf("%d", a);
f();
return 0;
}
Output:
10
30
20

7.b.Predict the output for the following code:


#include<stdio.h>
void main() {
auto int num ;
num= 20 ;
{
auto int num ;

Page 3 of 10
COMPUTATIONAL THINKING FOR STRUCTURED DESIGN

num= 60;
printf("Num : %d\n",num);
}
printf("Num : %d\n ",num);
}
Output:
Num : 60
Num : 20

7.c.Predict the output for the following code:


#include<stdio.h>
void increment(void);
void main() {
increment();
increment();
increment();
increment();
}
void increment(void)
{
auto int i = 0;
printf( "%d", i);
i=i+1;
}
Output:
0000
7.d. What is static storage class and predict the output to the following code?

#include<stdio.h>
void staticDemo() {
static int i;
{
static int j = 1;
printf("%d ", j);
j=j+1;
}
printf("%d\n", i);
i=i+1;
}
int main() {
staticDemo();
staticDemo();
}
Output:
1 0
21

7.e. Predict the output and trace the values.


#include<stdio.h>
static int gInt = 1;
static void staticDemo() {
static int i;
printf("%d ", i);
i=i+1;

Page 4 of 10
COMPUTATIONAL THINKING FOR STRUCTURED DESIGN

printf("%d\n", gInt);
gInt =gInt+1;
}
int main() {
staticDemo();
staticDemo();
}
Output:
0 1
1 2

8. a. Predict the output for the following code:


#include<stdio.h>
int fun();
int num = 5;
int main() {
fun();
printf("\nglobalnum value =%d \n",num); fun();
printf("\nglobalnum value =%d \n ",num); fun();
printf("\nglobalnum value =%d \n ",num); return 0;
}
int fun() {
static int num = 2;
printf("\nstaticnum value = %d \n",num); num=num+1;
return 0;
}
Output:
staticnum value = 4
globalnum value =5

8.b. Predict the output for the following code:


#include <stdio.h>
extern int a;
int main() {
printf ("%d", a);
}
int a = 20;

Output:
20
8. c. Predict the output for the following code:
#include<stdio.h>
int bomb();
int p;
int sum = 5;
int main() {
p = bomb();
printf("%d %d", sum, p);
return 0;
}
int bomb() {
sum=sum+1;
return (sum);

Page 5 of 10
COMPUTATIONAL THINKING FOR STRUCTURED DESIGN

Output:
6 6
8.d. Ram is poor at coding; he wants to find the output of the following program. But he couldn’t debug the code, help him to
output.
#include <stdio.h>
int main() {
register int n;
n = 20;
int *ptr;
ptr = &n;
printf("address of n : %u", ptr);
return 0;
}
Output:
Int n was stored in register.
So it’s an error
To get the address we have to store in memory

e. Kiran is a clever student in the class. He tries to solve every problem. But in coding classes he is not able to perform well. He g
stuck in predicting the output for the following code. Help him to predict the output.
#include<stdio.h>
void sum() {
static int a = 10;
static int b = 24;
printf("%d %d \n",a,b);
a=a+1;
b=b+1;
}
void main() {
int i;
sum();
sum();
sum();
}
Output:
10 24
11 25
12 26

9.a. Sajid is the peer mentor for the students, he should explain the students how static keyword works with
different data types. But he has some other tasks. Help students to predict the output for the following snippet.
#include<stdio.h>
static int p = 0;
void fun() {
auto int I = 1;
register char a = 'O';
p = p+1;
printf("%d %d %d\n", I, a, p);
p=3;
printf("%d %d %d\n", I, a, p);
}

Page 6 of 10
COMPUTATIONAL THINKING FOR STRUCTURED DESIGN

int main() {
auto int I = 1;
register char a = 'D';
p = p+1;
printf("%d %d %d\n", I, a, p);
fun();
printf("%d %d %d\n", I, a, p);
return 0;
}
Output:
1 68 1
1 79 2
1 79 3
1 68 3

9. b. Sameera wants to manipulate with the datatypes and now she is working on the conversion of character to
integer, while learning she found a snippet help understand the snippet and predict the output for it.
#include <stdio.h>
void sun(char);
void fun(int);
int main() {
char ssc = 12356;
sun(ssc);
}
void sun(char s) {
char f=s;
printf("%d \n",f);
char ss = 49;
fun(ss);
}
void fun(int s) {
int ss=s;
printf("%d",s);
}
Output:

68- We can’t store in char more than 255. so it is giving garbage value
49
9.c. Predict the output for the following code:
#include<stdio.h>
int count ;
extern int count;
void see();
void increment();
int main() {
count = 5;
increment(count);
}
void increment(void) {
if(count>0) {
count= count+1;
see(count);
}
else {

Page 7 of 10
COMPUTATIONAL THINKING FOR STRUCTURED DESIGN

count = 0;
see(count);
}
}
void see(void) {
printf("count is %d\n", count);
}

Output:
Count is 6

9.d. Samuel has a contest, which should be done within an hour, where he will get some codes to find the outputs.
He could solve all the problems, but he stuck at one problem. Help him to find the output.
#include <stdio.h>
int a, b, c = 0;
void prtFun(void);
int main () {
static int a = 2;
prtFun();
a=a+1;
prtFun();
printf ("\n %d %d ", a, b) ;
}
void prtFun (void) {
static int a = 4;
int b = 4;
a =a+b;
printf ("\n %d %d ", a, b);
}
Output:
84
12 4
30
9.e. Predict the output for the following code:
#include<stdio.h>
int main() {
register int i = 2;
static char ch = 'A';
auto float j;
int k;
printf("%d %c %f %d",i,ch,j,k);
k = ++ch && i;
printf("%d", k );
k = ++ch;
printf("%d", k );
j = i-- + ++k * 2;
printf("%d %f", k , j);
return 0;
}
Output:
2 A 0.115906 2194616768 138.000000

10. Most programmers will tell you that one of the ways to improve your performance in competitive

Page 8 of 10
COMPUTATIONAL THINKING FOR STRUCTURED DESIGN

programming is to practice a lot of problems. Our Janu took the above advice very seriously and decided to
set a target for herself. Janu decides to solve at least 10 problems every week for 4 weeks. Given the number
of problems she actually solved in each week over 4 weeks to an array using user console, output the
number of weeks in which Janu met her target.
#include <stdio.h>
int week(int p[]);
int week(int p[])
{
int count=0;
count= (p[0]>=10)? count=count+1:count;
count= (p[1]>=10)? count=count+1:count;
count= (p[2]>=10)? count=count+1:count;
count= (p[3]>=10)? count=count+1:count;
count= (p[4]>=10)? count=count+1:count;
printf("%d", count);
}
int main() {
int p[5];
printf("Enter 5 values:");
scanf("%d %d %d %d %d",&p[0],&p[1],&p[2],&p[3],&p[4]);
week(p);
}

11. In Raju’s land 2 different types of coconuts, type A and type B are there. Type A contains only X milliliters of
coconut water and type B contains only Y grams of coconut pulp. Rani’s nutritionist has advised her to
consume Xa milliliters of coconut water and Yb grams of coconut pulp every week in the summer. Find the total
number of coconuts (type A + type B) that Rani should buy from Raju each week to keep herself active in the hot
weather.
#include <stdio.h>
int coconut(int m,int n,int q,int r);
Int coconut(int m,int n,int q,int r)
{
int sum,ta,tb;
ta = q/m;
tb = r/n;
sum = ta + tb;
printf("ta:%d tb:%d\n",ta,tb);
printf("total coconuts required:%d\n",sum);

}
int main( )
{
int m,n,q,r; //type A have 'm' milliliters of coconut water
Printf(“Enter m,n,q,r values:”); //type B have 'n' grams of coconut pulp
scanf("%d %d %d %d",&m,&n,&q,&r); // 'q' required milliliters of coconut water
coconut(m,n,q,r); //'r' required grams of coconut pulp
return 0;

12. A hen lays one golden egg and one silver egg alternatively let us assume that a hen lays a golden egg on the first
day and so on. Now our task is to compute on which day 15th golden egg is laid. (Hint: 2*n-1)

Page 9 of 10
COMPUTATIONAL THINKING FOR STRUCTURED DESIGN

#include<stdio.h>
int egg(int n);
int egg(int n)
{
int day;
day=2*n-1;
printf("Day:%d\n",day);
}
int main( )
{
int n;
printf("enter n value:");
scanf("%d",&n);
egg(n);
return 0;
}

Page 10 of 10

You might also like