Professional Documents
Culture Documents
YEAR/SEM : III/6
4
04.02.2020 POINTOUT THE OUTPUT OF LOOPING & 22
CONDITIONING CODE SEGMENTS
7
25.02.2020 IMPLEMENTATION OF PRIME NUMBER 38
CONCEPTS
10
11.04.2020 CODE OPTIMIZATION AND MODULARITY 54
IMPLEMENTATION
13
19.05.2020 STUDY ON BASIC CONCEPTS OF COMPILE, LINK 76
AND OS
14
19.05.2020 PRACTICE PROBLEMS FOR CODE 81
IMPLEMENTATION
TASK 1
STUDY ON WORKING AND STORING OF DATA
DATA TYPES:
Data types in c refer to an extensive system used for declaring variables or functions of
different types. The type of a variable determines how much space it occupies in storage and
how the bit pattern stored is interpreted.
The types in C can be classified as follows:
Basic Types
They are arithmetic types and are further classified into: (a) integer types and (b) floating-
point types.
Enumerated types
They are again arithmetic types and they are used to define variables that can only assign
certain discrete integer values throughout the program.
The type void
The type specifier void indicates that no value is available.
Derived types
They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e)
Function types.
Integer Types
The following table provides the details of standard integer types with their storage sizes and
value ranges −
1
short 2 bytes -32,768 to 32,767
To get the exact size of a type or a variable on a particular platform, you can use
the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type
in bytes. Given below is an example to get the size of various type on a machine using
different constant defined in limits.h header file
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>
2
printf("ULONG_MAX : %lu\n", (unsigned long) ULONG_MAX);
printf("USHRT_MAX : %d\n", (unsigned short) USHRT_MAX);
return 0;
}
SAMPLE OUTPUT:
CHAR_BIT : 8
CHAR_MAX : 127
CHAR_MIN : -128
INT_MAX : 2147483647
INT_MIN : -2147483648
LONG_MAX : 9223372036854775807
LONG_MIN : -9223372036854775808
SCHAR_MAX : 127
SCHAR_MIN : -128
SHRT_MAX : 32767
SHRT_MIN : -32768
UCHAR_MAX : 255
UINT_MAX : 4294967295
ULONG_MAX : 18446744073709551615
USHRT_MAX : 65535
Floating-Point Types
The following table provide the details of standard floating-point types with storage sizes
and value ranges and their precision −
The header file float.h defines macros that allow you to use these values and other details
about the binary representation of real numbers in your programs. The following example
prints the storage space taken by a float type and its range values.
3
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>
return 0;
}
SAMPLE OUTPUT:
Storage size for float : 4
FLT_MAX : 3.40282e+38
FLT_MIN : 1.17549e-38
-FLT_MAX : -3.40282e+38
-FLT_MIN : -1.17549e-38
DBL_MAX : 1.79769e+308
DBL_MIN : 2.22507e-308
-DBL_MAX : -1.79769e+308
Precision value: 6
4
CHARACTER DATA TYPES :
Character data types are strings of characters. Upper and lower case alphabetic characters
are accepted literally. There is one fixed-length character data type: char, and two variable-
length character data types: varchar and long varchar. ... Char strings are padded with
blanks to the declared length.
CODE:
#include
void main() {
character2 = 'S';
printf("%c \n",character1);
printf("%c \n",character2);
}
SAMPLE OUTPUT:
Character1 & character2
R
S
Arrays:
An array is a collection of data items, all of the same type, accessed using a common name.
A one-dimensional array is like a list; A two dimensional array is like a table;
The C language places no limits on the number of dimensions in an array, though specific
implementations may.
CODE:
#include <stdio.h>
int main () {
int i,j;
5
/* initialize elements of array n to 0 */
return 0;
}
FUNCTIONS:
A function is a group of statements that together perform a task. Every C program has at least
one function, which is main(), and all the most trivial programs can define additional
functions.
You can divide up your code into separate functions. How you divide up your code among
different functions is up to you, but logically the division is such that each function performs
a specific task.
A function declaration tells the compiler about a function's name, return type, and
parameters. A function definition provides the actual body of the function.
The C standard library provides numerous built-in functions that your program can call. For
example, strcat() to concatenate two strings, memcpy() to copy one memory location to
another location, and many more functions.
A function can also be referred as a method or a sub-routine or a procedure, etc.
PROGRAM:
#include <stdio.h>
/* function declaration */
int main () {
6
/* local variable definition */
int a = 100;
int b = 200;
int ret;
return 0;
int result;
result = num1;
else
result = num2;
return result;
}
SAMPLE OUTPUT:
Max value is : 200
POINTERS:
Pointers in C are easy and fun to learn. Some C programming tasks are performed more
easily with pointers, and other tasks, such as dynamic memory allocation, cannot be
performed without using pointers. So it becomes necessary to learn pointers to become a
perfect C programmer. Let's start learning them in simple and easy steps.
7
As you know, every variable is a memory location and every memory location has its address
defined which can be accessed using ampersand (&) operator, which denotes an address in
memory. Consider the following example, which prints the address of the variables defined
.
PROGRAM 1:
#include <stdio.h>
int main () {
int var1;
char var2[10];
return 0;
}
SAMPLE OUTPUT:
Address of var1 variable: 1df9afec
Address of var2 variable: 1df9afe2
PROGRAM 2:
#include <stdio.h>
int main () {
int var = 20; /* actual variable declaration */
int *ip; /* pointer variable declaration */
ip = &var; /* store address of var in pointer variable*/
printf("Address of var variable: %x\n", &var );
/* address stored in pointer variable */
printf("Address stored in ip variable: %x\n", ip );
/* access the value using the pointer */
printf("Value of *ip variable: %d\n", *ip );
return 0; }
SAMPLE OUTPUT:
Address of var variable: 586b1244
Address stored in ip variable: 586b1244
Value of *ip variable: 20
8
NULL POINTER:
It is always a good practice to assign a NULL value to a pointer variable in case you do not
have an exact address to be assigned. This is done at the time of variable declaration. A
pointer that is assigned NULL is called a null pointer.
The NULL pointer is a constant with a value of zero defined in several standard libraries.
Consider the following program −
PROGRAM:
#include <stdio.h>
int main () {
int *ptr = NULL;
printf("The value of ptr is : %x\n", ptr );
return 0;
}
SAMPLE OUTPUT:
STRING:
Strings are actually one-dimensional array of characters terminated by a null character '\0'.
Thus a null-terminated string contains the characters that comprise the string followed by
a null.
The following declaration and initialization create a string consisting of the word "Hello".
To hold the null character at the end of the array, the size of the character array containing
the string is one more than the number of characters in the word "Hello."
PROGRAM :
#include <stdio.h>
int main () {
return 0;
SAMPLE OUTPUT:
Greeting message: Hello
9
TASK 2
POINT OUT THE ERRORS
1)
#include<stdio.h>
int main()
{
Int a= 35; float b = 3.24;
Printf(“%d %f %d”,a,b+1.25,235);
}
Reason: - It adds the values according to condition given 354.74 and return the value.
2)
#include<stdio.h>
int main()
{
int a,b,c;
scanf(“%d %d %d” , a,b,c);
}
Reason: -
Garbage value because of value and also address is not specified in the scanf.
3)
#include<stdio.h>
int main()
{
int m1,m2,m3;
printf(“enter values of marks in 3 subjects”);
scanf(“%d %d %d”,&m1,&m2,&m3);
printf(“you entered %d %d %d”,m1,m2,m3);
}
Reason: - Enter value of marks in 3 subjects
10
M1 = 10
M2 = 20 => 102030
M3 = 30[ combinely print the whole value]
4)
#include<stdio.h>
int main()
{
Float a = 15.5;
Char ch = ‘c’;
printf(a,ch);
Return 0 ;
}
printf(a,ch)
{
Reason: - return garbage value and value as “0”
5)
#include<stdio.h>
int main()
{
long num = 2;
printf(“%d /n”,num);
return 0;
}
Reason:- Here, the value will return as specified in the declaration
6)
#include<studio.h>
int main()
{
char ch = 200;
11
printf(“%d”,ch);
return 0 ;
}
Reason :- 56
7)
#include<stdio.h>
int main()
{
float a = 25.345;
int b = 25;
printf(“%lf %d /n”,a,b);
return 0 ;
}
Reason :- Return the int value “25”
8)
#include<stdio.h>
int main()
unsigned a = 25;
long unsigned b = 25;
printf(“%d u%u\n”,a,b);
return 0 ;
}
Reason :- 25 25
Here , the output as 25 25. Becasuse the function u is given.
9)
#include<stdio.h>
int main()
{
Int three[3][3] = { 2,4,3,6,8,2,2,3,1};
12
Printf(“%d /n”,three[1][1]); }
Reason :-
Because , we are painting the position value.given
Is [1][1]. The terminal value at position [1][1].
10)
#include <stdio.h>
int main()
{
Int ival;
Scanf(“%d /n” &ival);
Printf(“integer value = %d\n” ival);
Return 0 ;
}
Reason :
32654
123456
Integer value ; 3 2 6 5 4
11)
#include<stdio.h>
int main()
{
int dd,mm,yy;
printf(“enter data in dd/mm/yy format\n);
scanf(“%d %c %d %c %d %c” &dd,&mm,&yy);
printf(“the date is : %d %d %d \n” dd/mm/yy);
return ();
}
Reason :
The data is 18-12-2003
The given is separated by the condition (ie, dd-mm-yy.
So the year is separated by spaces.
13
12)
#include<stdio.h>
int main()
char text;
return 0 ;
Reason :- 12 3.45
Merry go round
It satisfies the condition and return the output statement.
13)
#include<stdio.h>
void show(int,float);
int main()
{
void(*s) (int,float);
s = show ;
(*s)(10,3.14);
return 0;
}
void show(int ; float f)
{
printf(“%d %f \n”, I,f);
}
Reason :-
103.140000
The values given are combined together and returned the values by 103.140000.
14
14)
#include<stdio.h>
Void main()
{
int a,b;
scanf(“%d %d”,a,b);
If(a>b):
printf(“the game”);
else:
printf(“you play”);
return 0 ;
}
Reason : this is prime only if when there is only “&” in the scanf statement .
15)
#include<stdio.h>
int main()
{
static int count = 5;
printf(“count = %d” ,count --)
if (count != 0)
{
main();
{
Return 0;
}
Reason :
The count value starts from “5” and the value is decrement and the values are decreased to 0
and return as “54321”.
15
TASK 3
FIND THE OUTPUT OF THE GIVEN CODE SEGMENTS
1)
include<stdio.h>
int main()
{
int i = 2;
#ifdef DEF
i *= i;
#else
printf("\n%d", i);
#endif
return 0;
}
REASON :-
Directly assigning the value of “I” as the l-value to i
2)
include<stdio.h>
#define PRODUCT(x) (x*x)
int main()
{
int i = 3, j, k;
j = PRODUCT(i++);
k = PRODUCT(++i);
16
Reason :- 12 49
Here ,the values of I increment by I and get multiplied with previous value so the
increment value gets increment upto 7 and multiplies and gives output 49.
3)
include<stdio.h>
#define PI 3.14
#define AREA(x,y,z) PI*x*x+y*z
int main()
{
float a = AREA(1, 5, 8);
float b = AREA(AREA(1, 5, 8), 4, 5);
printf("a = %f\n", a);
printf("b = %f\n", b);
return 0;
}
Reason :-
a = 43.199
b = 195.4595
considering area value for abc we have a = 43.1399 and the resultant with (4,5) and the
output is returned.
4)
#include<stdio.h>
int main()
{
int n[3][3] = {
2, 4, 3,
6, 8, 5,
3, 5, 1
};
17
printf("\n%d %d %d", *n, n[3][3], n[2][2]);
return 0;
}
Reason :-
Returns garbage as 7826292801 because the two values of different columns and rows are
not possible to display.
5)
#include<stdio.h>
int main()
{
int n[3][3] = {
2, 4, 3,
6, 8, 5,
3, 5, 1
};
int i, *ptr;
ptr = n;
for (i = 0; i <= 8; i++)
printf("\n%d", *(ptr + i));
return 0;
}
Reason :-
23831 [ depends upon the values of the row & columns in 4655 their
index values . ]
6)
#include<stdio.h>
int main()
{
int n[3][3] = {
2, 4, 3,
6, 8, 5,
18
3, 5, 1
};
int i, j;
for (i = 0; i <= 2; i++)
for (j = 0; j <= 2; j++)
printf("\n%d %d", n[i][j], *(*(n + i) + j));
return 0;
}
Reason :-
23831 [ depends upon the values of the row & columns in 4655 their
index values . ]
7)
#include<stdio.h>
int main()
{
char c[2] = "A";
printf("\n%c", c[0]);
printf("\n%s", c);
return 0;
}
Reason :-
A
A
Because the condition is given for printing the double character in both lower & upper
cases.
8)
#include<stdio.h>
int main()
{
char s[] = "Get organised! learn C!!";
printf("\n%s", &s[2]);
19
printf("\n%s", s);
printf("\n%s", &s);
printf("\n%c", s[2]);
return 0;
}
Reason :-
Get organised ! learn c !!
Get organised ! learn c !!
Because the repletion is given as 2 times for the problem in the condion as s[2]
9)
#include<stdio.h>
int main()
{
char s[] = "No two viruses work similarly";
int i = 0;
while (s[i] != 0)
{
printf("\n%c %c", s[i], *(s + i));
printf("\n%c %c", i[s], *(i + s));
i++;
}
return 0;
}
Reason :-
The condition is given as specifying the string as printing them two times even with the
spaces].
10)
#include<stdio.h>
int main()
{
20
printf(5 + "Good Morning ");
return 0;
}
Reason :-
Morning
It will start printing from 5th position by considering its index value.
Result:
21
TASK 4
POINTOUT THE OUTPUT OF LOOPING & CONDITIONING CODE SEGMENTS
1)
#include<stdio.h>
int main()
{
int a=300,b,c;
if(a>=400)
b=300;
c=200;
printf(“%d%d\n”,b,c);
return 0;
}
REASON :
It generate the garbage values and with no error in the code . To generate the output ,
the “&” symbols in printf statement should be removed and then ruined to get the output as
300,200
2)
#include<stdio.h>
int main()
{
int a=500,b,c;
if(a>=400)
b=300;
c=200;
printf(“%d %d\n”,b,c);
return 0;}
Reason : it generate the output as “300,200” with no errors in the code.
22
3) #include<stdio.h>
int main()
{
int x=10,y=20;
if(x==y);
printf(“%d%d\n”,x,y);
return 0;
}
Reason : it generate the as “1020” with no error in the code.
4) #include<stdio.h>
int main()
{
int x=3;
float y=3.0;
if(x==y)
printf(“x and y are equal\n”);
else
printf(“x and y are not equal”);
return 0;
}
Reason :- It returns the output as x and y are equal. Because “x” value is equal to y
value. It compares and satisfies the condition. Then it returns the first printf statement.
5) #include<stdio.h>
int main()
{
int x=3,y,z;
y=x=10;
23
z=x<10;
printf(“x=%dy=%dz=%d\n”,x,y,z);
return 0;
}
Reason :-
X = 10 , y = 10,z=0
6) #include<stdio.h>
int main()
{
int i=65;
char j=’A’;
if(i==j)
printf(“C is wow\n”);
else
printf(“ C is headache\n”);
return 0; }
Reason :-
It will return the output as “c is wow” . because here I,j value is taken ascii value of
a . hence I = 65 ,j = 65. Then satisfies the condition and print the statement “ c is
wow”.
7)
#include<stdio.h>
int main()
{
float a=12.25, b=12.52;
if(a=b)
printf(“a and b are equal\n”);
return 0;
}
24
Reason :-
A and b are equal. In float , it will consider the element before the decimal part.
8)
# include<stdio.h>
int main()
{
int j=10,k=12;
if(k>=j)
{
{
k=j;
j=k;
}
}
return 0;
}
Reason :-
No return value. Because , at initial given condition k>=j it satisfices the condition
and went fro swapping which will return the same value as output.
9)
#include<stdio.h>
int main()
{
if(‘X’<’x’)
printf(“ascii value of X is smaller than that of x\n”);
}
Reason :- ascii values of x is smaller than that of x. because by comparing the ascii
values of the two character.
25
10)
#include<stdio.h>
int main()
{
int x=10;
if(x>=2) then
printf(“%d\n”,x)
return 0;
}
Output :- 10
Result:
26
TASK 5
BASIC NUMBER THEORY - 1
Instructions:
1)Two boys, Venky and Sagar, are at war over a girl, Riu. Driven by their feelings, they
decided to confess to Riu. Since both of them were equally dumb, Riu decided that she
would go out with that boy who would successfully find the pattern and thus prove that he is
less dumb.
Given : 0<=N<=10^18
Sample input
1
2
3
10
100
Sample Output
1
2
3
11
121
PROGRAM :
#include <stdio.h>
long int dec2bas(long int n);
int main()
{
long int a;
do{
if(scanf("%ld",&a)!=EOF)
printf("%ld\n",dec2bas(a));
else
27
break;
}
while(1);
return 0;
}
long int dec2bas(long int n)
{
if(n<9)
return n;
return n%9 + 10*dec2bas(n/9);
}
1. 2) Little Panda has a thing for powers and modulus and he likes challenges. His friend Lucy,
however, is impractical and challenges Panda to find both positive and negative powers of a
number modulo a particular number. We all know that A-1mod X refers to the modular inverse
of A modulo X. Since Lucy is impractical, she says that
A-nmodX=(A-1modX)n for n>0. Now she wants Panda to compute ABmodX. She also thinks
that this problem can be very difficult if the constraints aren't given properly. Little Panda is
very confused and leaves the problem to the worthy programmers of the world. Help him in
finding the solution.
Input Format
The first line contains T, the number of test cases.
Then T lines follow, each line containing A,B and X .
Output Format
Output the value of ABmodX .
Constraints
1≤T≤1000
1≤A≤106
-106≤B≤106
1≤X≤106
A and X are coprime to each other.
28
Sample Input
3
123
342
4 -1 5
Sample Output
1
1
4
PROGRAM :
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
long long int gcd(long long int a,long long int bp);
long long int powr(long long int a,long long int b,long long int p);
long long int mul_inv(long long int a,long long int b);
int main() {
long long int k,a,b,x,i,j,ans=0;
scanf("%lld",&k);
while(k>0)
{
scanf("%lld %lld %lld",&a,&b,&x);
if(b>=0)
{
i=a;
}
else
{
29
i=mul_inv(a,x);
b=-b;
}
printf("%lld\n",powr(i,b,x)%x);
k--;
}
return 0;
}
long long int powr(long long int a,long long int b,long long int p)
{
a=a%p;
long long int ans=1;
long long int k=(a*a)%p;
if(b==0)
{
return 1;
}
if(a==0)
{
return 0;
}
if(b%2==0)
ans=powr(k,(b/2),p);
else
ans=(a*powr(k,((b-1)/2),p))%p;
return ans;
}
30
if (b == 1) return 1;
while (a > 1) {
q = a / b;
t = b, b = a % b, a = t;
t = x0, x0 = x1 - q * x0, x1 = t;
}
if (x1 < 0) x1 += b0;
return x1;
}
long long int gcd(long long int a,long long int bp)
{
long long int temp,p1=1,p2=0,p0=0,q[3],b=bp,bt=bp,cn=0;
q[2]=q[1]=q[0]=0;
if(a<b)
{
temp=b;
b=a;
a=temp;
}
temp=a%b;
q[2]=(a/b);
a=b;
b=temp;
temp=a%b;
q[1]=(a/b);
a=b;
b=temp;
while(b!=0)
{
temp=a%b;
q[0]=(a/b);
a=b;
31
b=temp;
p0=(p2-(p1*q[2]))%bt;
p0=(p0+bt)%bt;
p2=p1;
p1=p0;
q[2]=q[1];
q[1]=q[0];
cn++;
}
p0=(p2-(p1*q[2]))%bt;
p0=(p0+bt)%bt;
return p0;
}
Result:
32
TASK 6
BASIC NUMBER THEORY – 2
Instructions:
1) The Monk wants to teach all its disciples a lesson about patience, since they are
always in a hurry to do something crazy. To teach them this, he gives them a list
of N numbers, which may or may not be distinct. The students are supposed to solve a
simple Mathematical equation based on the array of these N numbers.
Input constraints:
The first line of input will contain an integer — N. The next line will contain N integers
denoting the elements of the list.
Output constraints:
Print the required answer of the equation.
Constraints:
1 ≤ N ≤ 50
1 ≤ Ai ≤ 103
Sample input
2
26
33
Sample O/P
144
PROGRAM :
#include <stdio.h>
#include <stdlib.h>
main()
{
int input,gcd,i,*arr;
unsigned long long mul=1,ans=1;
scanf("%d",&input);
arr=(int *)malloc(sizeof(int)*input);
for(i=0;i<input;i++)
scanf("%d",&arr[i]);
gcd=arr[0];
for(i=0;i<input-1;i++)
{
gcd=cal_gcd(gcd,arr[i+1]);
if(gcd==1)
break;
}
for(i=0;i<input;i++)
{
mul=mul*arr[i];
mul%=1000000007;
}
for(i=0;i<gcd;i++)
{
ans=ans*mul;
ans%=1000000007;
}
34
printf("%llu",ans);
}
cal_gcd(int A,int B)
{
int tmp;
tmp=A;
A=B;
B=tmp%B;
if(B==0)
return A;
else
cal_gcd(A,B);
}
2) There are N ants staying at the vertices of the N-regular polygon (one ant at one
vertex). At some moment of time all the ants choose one of the edges their vertex is adjacent
to and start walking along this edge. If two ants meet at some point of the edge they die.
Please find the probability that all the ants will survive.
Input
The first line contains one integer T - number of test cases. The following T lines contain
one integer each - N.
Output
We can consider answer as a fraction P / Q. For each test case output P * Q-1 modulo 109 +
7.
Constraints
• T <= 1000
35
SAMPLE INPUT
SAMPLE OUTPUT
250000002
PROGRAM
#include<stdio.h>
int main()
{
long long unsigned n;
int t,i,j;
scanf("%d",&t);
for(i=0;i<=t-1;i++)
{long long int result=1,x;
int mod=1000000007;
scanf("%llu",&n);
n=n-1;
x=2;
while(n>0)
{
if(n & 1)
{
result=(result*x)%mod;
}
n=n>>1;
x=(x*x)%mod;
}
int m0=mod;
int y=0,z=1;
while(result>1)
{
36
int q=result/mod;
int t=mod;
mod=result%mod;
result=t;
t=y;
y=z-q*y;
z=t;
}
if(z<0)
{
z+=1000000007;
}
printf("%d\n",z);
}
return 0;
}
Result:
37
TASK 7
Instructions:
1) Ashu is very fond of Prime numbers and he like challenging his friends by giving
them various problems based on Mathematics and Prime number. One of his friend Harshit
is jealous and challenges him to solve a task. Task is :
Given a prime number X, you need to give the count of all numbers in range 1 to
106 inclusive which have minimum prime factor X.
Help Ashu in solving this task.
Input:
First line consist of numer of test cases T.
Each test case contains a single number X.
Output:
Output for each test case count of all numbers in range 1 to 106 inclusive which have
minimum prime factor X.
Constraints:
1 ≤ T ≤ 105
Prime number X where 2 ≤ X ≤ 106
SAMPLE INPUT
11
38
SAMPLE OUTPUT
500000
20779
PROGRAM :
#include <stdio.h>
int p[1000100]={0};
int a[1000100]={0};
int main()
{
int i,j,x,mc,n;
p[0]=1;
p[1]=1;
for(i=2;i*i<=1000000;i++)
{
mc=0;
if(p[i]!=0)
continue;
p[i]=1;
mc++;
for(j=2;j*i<=1000000;j++)
{
if(!p[i*j])
{
p[j*i]=1;
mc++;
}
39
a[i]=mc;
}
for(i=0;i<=1000000;i++)
{
if(p[i]==0 && a[i]==0)
a[i]=1;
}
scanf("%d",&n);
while(n--)
{
scanf("%d",&x);
printf("%d",a[x]);
printf("\n");
}
return 0;
}
SAMPLE INPUT
3
51
12
65
SAMPLE OUTPUT
53
40
11
67
PROGRAM :
#include<stdio.h>
#include<math.h>
void solution();
void sieve();
char isPrime[1000000];
int main(){
sieve();
unsigned long long t;
scanf("%llu",&t);
while(t--){
unsigned long long n;
scanf("%llu",&n);
solution(n);
}
}
void solution(unsigned long long n){
for(unsigned long long i=1;;i++){
if(isPrime[n]==1){
printf("%llu\n",n);
break;
}
else if(isPrime[n-i]==1){
printf("%llu\n",n-i);
break;
}
else if(isPrime[n+i]==1){
printf("%llu\n",n+i);
break;
}
41
}}
void sieve(){
for(unsigned long long i=0;i<sizeof(isPrime);i++)
isPrime[i]=1;
isPrime[0]=0;
isPrime[1]=0;
for(unsigned long long i=2;i<=(unsigned long
long)(lround(sqrt(1000000)));i++){
if(isPrime[i]==1){
unsigned long long mul=2;
for(unsigned long long j=i;j*i<sizeof(isPrime);j++)
isPrime[i*j]=0;
}
}
}
Result:
42
TASK 8
IMPLEMENTATION OF PRIMALITY TEST
Instructions:
1) You are required to distribute N bananas among some people according to the
following conditions:
Write a program to determine whether the bananas can be distributed among the people.
Input format
Output format
For each test case, print Yes or No depending upon the result.
Constraints
2≤T≤105
1≤N≤106
SAMPLE INPUT
2
2
4
43
SAMPLE OUTPUT
No
Yes
PROGRAM :
#include<stdio.h>
#include<stdbool.h>
#include<malloc.h>
#include <math.h>
int main() {
int T;
scanf("%d", &T);
for(int t_i=0; t_i<T; t_i++)
{
int N;
scanf("%d", &N);
44
2) Alfi asked Roy to go for shopping with her. Witty Roy came up with a condition. He
said, for each product of MRP (Maximum Retail Price) R, she'll have to pay minimum of all
the prime factors of R and he himself will pay rest of the amount. Without giving it a second
thought Alfi agreed.
Now they bought N number of products. You're to find how much money did Roy had to
pay for each product.
Input:
Output:
Print single integer in a new line, the amount of money Roy had to pay for each product.
Constraints:
2<=N,R<=1000000
SAMPLE INPUT
2
5
10
SAMPLE OUTPUT
0
8
45
PROGRAM :
#include <stdio.h>
#include <stdlib.h>
#define pcx putchar_unlocked
#define gcx getchar_unlocked
typedef long int lint;
int main () {
for (lint ni=0; ni<PLTsz; ++ni) spFact[ni] =ni;
46
for (lint ni=4; ni<PLTsz; ni+=2) spFact[ni] =2;
for (lint pn=3; pn<PLTsz; pn+=2) {
if (pn == spFact[pn]) {
for (lint ni=pn; ni<=PLTsz; ni+=pn)
if (ni==spFact[ni]) spFact[ni] = pn;
}
}
lint T = getli() +1;
while(--T) {
lint MRP = getli();
if (MRP==spFact[MRP]) putli(0, '\n');
else putli(MRP-spFact[MRP], '\n');
}
return 0;
}
Result:
47
TASK 9
DATA STRUCTURE ALGORITHMS
Write the procedure, program and output and also mention the time complexity.
1. Linked List
After getting her PhD, Christie has become a celebrity at her university, and her facebook
profile is full of friend requests. Being the nice girl she is, Christie has accepted all the
requests.
Now Kuldeep is jealous of all the attention she is getting from other guys, so he asks her to
delete some of the guys from her friend list.
To avoid a 'scene', Christie decides to remove some friends from her friend list, since she
knows the popularity of each of the friend she has, she uses the following algorithm to
delete a friend.
Algorithm
Delete(Friend):
DeleteFriend=false
for i = 1 to
Friend.length-1
if (Friend[i].popularity <
Friend[i+1].popularity) delete i th friend
DeleteFriend=true break
if(DeleteFriend == false)
delete the last friend
Input:
First line contains T number of test cases. First line of each test case contains N, the number
of friends Christie currently has and K ,the number of friends Christie decides to delete.
Next lines contains popularity of her friends separated by space.
Output:
48
For each test case print N-K numbers which represent popularity of Christie friend's after
deleting K friends.
Constraints
1<=T<=1000
1<=N<=100000
0<=K< N
0<=popularity_of_friend<=100
NOTE:
Order of friends after deleting exactly K friends should be maintained as given in input.
SAMPLE INPUT
3
31
3 100 1
52
19 12 3 4 17
53
23 45 11 77 18
SAMPLE OUTPUT
100 1
19 12 17
77 18
2. Stacks
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {)
occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three
types of matched pairs of brackets: [], {},and ().
49
A matching pair of brackets is not balanced if the set of brackets it encloses are not matched.
For example, {[(])} is not balanced because the contents in between { and } are not
balanced. The pair of square brackets encloses a single, unbalanced opening bracket, (, and
the pair of parentheses encloses a single, unbalanced closing square bracket, ].
By this logic, we say a sequence of brackets is balanced if the following conditions are met:
INPUT:
CONSTRAINTS:
1<=n<=10^3
1<=|s|<=10^3, where is the length of the
sequence. All chracters in the sequences ? { {, },
(, ), [, ] }.
OUTPUT:
SAMPLE INPUT
3
{[()]}
{[(])}
{{[[(())]]}}
50
SAMPLE OUTPUT
YES
NO
YES
Explanation
1.The string {[()]} meets both criteria for being a balanced string, so we print YES on a new
line.
2.The string {[(])} is not balanced because the brackets enclosed by the matched pair { and
} are not balanced: [(]).
3.The string {{[[(())]]}} meets both criteria for being a balanced string, so we print YES on
a new line.
3. QUEUE
• Every day you are provided with one disk of distinct size.
• The disk with larger sizes should be placed at the bottom of the tower.
• The disk with smaller sizes should be placed at the top of the tower.
• You cannot put a new disk on the top of the tower until all the larger disks that are
given to you get placed.
Print N lines denoting the disk sizes that can be put on the tower on the ith day.
Input format
• First line: N denoting the total number of disks that are given to you in the N
subsequent days
• Second line: N integers in which the ith integers denote the size of the disks that are
given to you on the ith day
Note: All the disk sizes are distinct integers in the range of 1 to N.
51
Output format
Print N lines. In the ith line, print the size of disks that can be placed on the top of the
tower in descending order of the disk sizes.
If on the ith day no disks can be placed, then leave that line empty.
Constraints
1≤N≤106
1≤size of a disk≤N
SAMPLE INPUT
5
45123
SAMPLE OUTPUT
4
321
Explanation
On the first day, the disk of size 4 is given. But you cannot put the disk on the bottom of the
tower as a disk of size 5 is still remaining.
On the second day, the disk of size 5 will be given so now disk of sizes 5 and 4 can be
placed on the tower.
On the third and fourth day, disks cannot be placed on the tower as the disk of 3 needs to be
given yet. Therefore, these lines are empty.
On the fifth day, all the disks of sizes 3, 2, and 1 can be placed on the top of the tower.
Given an array A of N integers, classify it as being Good Bad or Average. It is called Good,
if it contains exactly X distinct integers, Bad if it contains less than X distinct integers and
Average if it contains more than X distinct integers.
52
Input format:
First line consists of a single integer T denoting the number of test cases.
First line of each test case consists of two space separated integers denoting N and X.
Second line of each test case consists of N space separated integers denoting the array
elements.
Output format:
Print the required answer for each test case on a new line.
Constraints:
1≤T≤50
1≤X,N≤13000
1≤A[i]≤109
SAMPLE INPUT
4
41
1425
42
42
15
43
5241
44
1245
SAMPLE OUTPUT
Average
Average
Average
Good
Result:
Thus, the implementing of program is successfully executed and O/P is verified.
53
TASK 10
CODE OPTIMIZATION AND MODULARITY IMPLEMENTATION
In 2018, Shourya learned about a serious Android bug: in the burger emoji, the cheese was
directly on top of the lower bun, rather than on the patty itself. Really, who makes a burger
that way? Shourya, vowed to drop everything and address this issue immediately.
To prevent this sort of situation in the future, the ANC (Algorithms and Coding ) Core
team has constructed a mathematical model for understanding burgers. A burger consists of
a stack of K ingredients between two buns, with each ingredient appearing exactly once.
We are interested in the distance-to-bun value of each ingredient. The distance-to-bun
value of an ingredient is the minimum number of other ingredients between the that
ingredient and a bun:
• If K is even, then the distance-to-bun values for the ingredients (starting with the
ingredient at the top of the stack) are: 0,1,...,K/2−1,K/2−1,...,1,0.
• If K is odd, then they are: 0,1,...,((K−1)/2)−1,(K−1)/2,((K−1)/2)−1,...,1,0.
After carrying out a lot of focus group testing (and eating a lot of burgers), we have
determined that the i-th of each of our K ingredients has an optimal distance-to-bun value of
Di. We think our burger emoji users will be happiest if we choose an ordering for our
ingredients that minimizes the error value, which we define as the sum of the squared
differences between each ingredient's optimal and actual distance-to-bun values.
Given the list of optimal distance-to-bun values for our ingredients, can you help us
determine the smallest possible error?
Input
The first line of the input gives the number of test cases, T; T test cases follow. Each begins
with one line containing an integer K: the number of ingredients in our burger. Then, there
54
is one more line containing K integers Di, the optimal distance-to-bun values of our
ingredients.
Output
For each test case, output one line containing the smallest possible error, as described above.
Constraints
1 ≤ T≤ 100.
0 ≤ Di≤ floor((K-1)/2), for all i (Each optimal distance-to-bun value is within the range of
attainable distance-to-bun values.)
1≤K≤1000
SAMPLE INPUT
3
5
02112
1
0
6
222222
SAMPLE OUTPUT
2
0
10
Explanation
Sample Case 1 is the one illustrated in the problem statement.
In Sample Case 2, there is only one ingredient in the burger; that is not much of a burger,
but our model has to be able to handle this base case! There is no confusion over how to
place the one ingredient, and the error is 0.
55
In Sample Case 3, there are six ingredients, but all of them have an optimal distance-to-bun
of 2.
Any way of placing them is equivalent, and the error is 22 + 12 + 02 + 02 + 12 + 22 = 10.
PROGRAM :
#include<stdio.h>
void merge(int arr[], int l, int m, int r);
void mergeSort(int arr[], int l, int r);
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int k;
scanf("%d",&k);
int a[k],b[k];
if (k%2==1)
{b[(k-1)]=(k-1)/2;
for (int i=0;i<(k-1)/2;i++)
{b[2*i]=i;
b[2*i+1]=i;}}
else
for (int i=0;i<k/2;i++)
{
b[2*i]=i;
b[2*i+1]=i;
}
for (int i=0;i<k;i++)
{scanf("%d",&a[i]);}
mergeSort(a,0,k-1);
int sqsum=0;
56
for (int i=0;i<k;i++)
{
sqsum=sqsum+(a[i]-b[i])*(a[i]-b[i]);
}
printf("%d\n",sqsum);
}
}
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
57
else
{
arr[k] = R[j];
j++;
}
k++;
}
58
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
Result:
59
TASK 11
PARTIAL CODE COMPLETION
1) Cut the sticks:
You are given N sticks, where each stick has the length of a positive integer. A cut operation
is performed on the sticks such that all of them are reduced by the length of the smallest
stick. Suppose we have six sticks of the following lengths:
544228
Then, in one cut operation we make a cut of length 2 from each of the six sticks. For the
next cut operation four sticks are left (of non-zero length), whose lengths are the following:
3226
The above step is repeated until no sticks are left.
Given the length of N sticks, print the number of sticks that are cut in subsequent cut
operations.
Input Format
The first line contains a single integer NN.
The next line contains NN integers: a0,a1,…,aN−1a0,a1,…,aN−1separated by
space, where airepresents the length of ithstick.
Output Format
For each operation, print the number of sticks that are cut in separate line.
60
PROGRAM:
#include <stdio.h>
#include <string.h>
#include
<math.h>
#include
<stdlib.h> int
main ( )
{
int n;
scanf("%d",
&n); int a[n-
1];
for(inti=0;i<n
;++i)
{
int stick;
scanf("%d",&stick);
a[i]=stick;
}
int
f=0;
do
{
int count=0,small=99;
f=0;
for(inti=0;i<n;++i)
{
if(a[i]>0&&a[i]<small)
small=a[i];
}
for(inti=0;i<n;++i)
61
{
if(a[i]!=0)
{
a[i]=a[i]-small;
++count;
f=1;
}
}
if(count)
printf("%d\n",count);
}while(f==1);
return 0;
}
2) One Egg
“One Egg” is an egg supply company which supplies eggs to retailers. They have M classes
of eggs. Each class can have N number of eggs (N can be the same or can vary class to class).
They accept order via mail for X eggs. In response, they confirm if they can supply the eggs
with a “Thank you” note and the number of eggs or with a “Sorry” note and the numbers of
eggs they can supply. They also mention the breakdown of eggs by the class they will supply.
The ordered eggs are adjusted against the different classes with the most number of eggs
adjusted first then the balance is adjusted against the second-highest and so on. The
company is a bit superstitious as well. If the number of eggs ordered is greater than or equal
to the total number of eggs in stock then they retain one egg and responds back with the
“Sorry” note with total number of eggs in stock minus one and breakdown of eggs by class.
Note: If the classes have the same number of eggs then class entered first should be selected
to adjust.
62
Input Format:
First line contains two space-separated integers denoting the respective values of M (the
number of classes of eggs) and X, the number of eggs ordered The following M lines contain
an integer each indicating the number of eggs available in each class Output Format:
First line should be, if X is less than total number of Eggs then Print ” Thank you, your
order for X eggs is accepted” Else if X is greater than or equal to total number of Eggs then
print ” ” Sorry, we can only supply (total number of Eggs in stock -1) eggs” T hen M lines
with 3 columns: First column – Number of eggs available in each class Second column –
Eggs allocated against each class for that order Third column – Balance Eggs against each
class
Constraints:
1 ≤ M ≤ 20 N ≥ 1 X ≥ 1
Sample Input 1:
5 150
50
15
80
10 5
Sample Output 1:
50 50 0
15 15 0
80 80 0
10 5 5
5 0 5
63
Explanation:
Total order of 150 eggs is less than the total number of Eggs 50+15+80+10+5 = 160. Hence
the Thank you message. 150 was first adjusted against Class with the first highest number
of eggs
80. Balance of 150-80 = 70 was adjusted against the second highest class of 50. Balance of
70-50 = 20 then adjusted against 15. Balance of 20-15 = 5 then adjusted against 10 leaving
behind 5
Sample Input 2:
4 250
80
50
70
20
Sample Output 2:
80 80 0
50 50 0
70 70
0 20 19
1
Explanation:
The total order of 250 eggs was greater than the total number of eggs 80+50+70+20 = 220.
Hence the sorry message. 250 was first adjusted against Class with the first highest number
64
of eggs 80. Balance of 250-80 = 170 was adjusted against the second highest class of 70.
Balance of 170-70 = 100 was then adjusted against 50. Balance of 100-50 = 50 then adjusted
against 20.
Since Balance is greater than the last class of egg all but one egg is left in that last class.
Solution:
#include
<stdio.h> int
main() {
int m,x,i,a[1000],sum=0,s;
scanf("%d %d",&m,&x);
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}
if(su
m>x)
printf("Thank you, your order for %d eggs are
accepted\n",x); else {
printf("Sorry, we can only supply %d eggs\n",sum-1);
x=sum-1;
}
for(i=0;i<m;i++)
{
if(x>=a[i])
{
printf("%d\t%d\t%d\n",a[i],a[i],0);
x=x-a[i];
}
else if(x<a[i])
65
{
s=a[i]-
x;
printf("%d\t%d\t%d\n",a[i],x,s);
x=0;
}
else if(x==0)
printf("%d\t%d\t%d\n",a[i],0,a[i]);
}
ret
ur
n
0;
}
3) Bride Hunting
Sam is an eligible bachelor. He decides to settle down in life and start a family. He goes
bride hunting. He wants to marry a girl who has at least one of the 8 qualities mentioned
below:- 1) The girl should be rich.
He is in search of a bride who has some or all of the 8 qualities mentioned above. On bride
hunting, he may find more than one contenders to be his wife.
66
In that case, he wants to choose a girl whose house is closest to his house. Find a bride for
Sam who has maximum qualities. If in case, there are more than one contenders who are at
equal distance from Sam’’s house; then print ““Polygamy not allowed””.
In case there is no suitable girl who fits the criteria then print “”No suitable girl found””
Given a Matrix N*M, Sam’s house is at (1, 1). It is denoted by 1. In the same matrix, the
location of a marriageable Girl is also denoted by 1. Hence 1 at location (1, 1) should not be
considered as the location of a marriageable Girl’s location.
The qualities of that girl, as per Sam’’s criteria, have to be decoded from the number of non-
zero neighbors (max 8-way) she has. Similar to the condition above, 1 at location (1, 1)
should not be considered as the quality of a Girl. See Example section to get a better
understanding.
Find Sam, a suitable Bride and print the row and column of the bride, and find out the
number of qualities that the Bride possesses.
NOTE: Distance is calculated in number of hops in any direction i.e. (Left, Right, Up, Down
and Diagonal)
Input Format:
• First Line contains the row (N) and column (M) of the houses.
• Next N lines contain the data about girls and their qualities.
Output Format:
It will contain the row and column of the bride, and the number of qualities that Bride
possess separated by a colon (i.e. :).
Sample Input 1:
29
101101111
000101001
Sample Output
1: 1:7:3
67
Explanation:
The girl and qualities are present at (1,3),(1,4),(1,6),(1,7),(1,8),(1,9),(2,4),(2,6),(2,9).
The girl present at (1,3) has 2 qualities (i.e. (1,4)and (2,4)).
The girl present at (1,4) has 2 qualities.
The Bride present at (1,6) has 2 qualities.
The Bride present at (1,7) has 3 qualities.
The Bride present at (1,8) has 3 qualities.
The Bride present at (1,9) has 2 qualities.
The Bride present at (2,4) has 2 qualities.
The Bride present at (2,6) has 2 qualities.
The Bride present at (2,9) has 2 qualities.
As we see, there are two contenders who have maximum qualities, one is at (1,7) and
another at (1,8).
The girl who is closest to Sam’s house is at (1,7). Hence, she is the bride.
Hence, the output will be 1:7:3.
Sample Input 2:
66
100000
000000
001110
001110
001110
000000
Sample Output
2: 4:4:8
Explanation:
The bride and qualities are present at
(3,3),(3,4),(3,5),(4,3),(4,4),(4,5),(5,3),(5,4),(5,5) The Bride present at (3,3) has 3
qualities (i.e. (3,4),(4,3) and (4,4)).
The Bride present at (3,4) has 5 qualities.
The Bride present at (3,5) has 3 qualities.
The Bride present at (4,3) has 5 qualities.
The Bride present at (4,4) has 8 qualities.
68
The Bride present at (4,5) has 5 qualities.
The Bride present at (5,3) has 3 qualities.
The Bride present at (5,4) has 5 qualities.
The Bride present at (5,5) has 3 qualities.
As we see, the girl present in (4,4) has the maximum number of Qualities. Hence, she is the
bride.
Hence, the output will be 4:4:8.
PROGRAM :
#include<st
dio.h> int
main() {
int
n,m,i,g[50][50],j,p,q,max=0,cnt=0,k=1,c=0,u=1,x[30],y[30],t1,min=0
, sc[50],e,f,ct=0,a[50],count=0,t2=0,t=0; scanf(“%d
%d”,&n,&m);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
scanf(“%d”,&g[i][j]);
}
}
g[1][1]=
0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cnt=0;
69
if(g[i][j]==1
)
{
t++;
for(p=i-1;p<=i+1;p++)
{
for(q=j-1;q<=j+1;q++)
{
if(g[p][q]==1)
{
cnt++;
}
}
}cnt=cnt-1;
a[k]=cnt;
k++;
}
}
}
for(k=1;k<=t;k++)
{
if(a[k]>max)
max=a[k];
}
if(max==0)
{
printf(“No suitable girl found”);
return 0;
}
for(k=1;k<=t;k++)
70
{
if(a[k]==max)
c++;
}
for(k=1;k<=t;k++)
{
t2=0;
if(a[k]==max)
{
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(g[i][j]==1)
t2++;
if(t2==k)
{
x[u]=i;
y[u]=j;
u++;
}
}
}
}
}
t1=u-1;
if(c==1)
printf(“%d:%d:%d”,x[1],y[1],max);
else
{
for(u=1;u<=t1;u++)
71
{
sc[u]=sqrt(((x[u]-1) * (x[u]-1)) + ((y[u]-1)*(y[u]-1)));;
}
min=sc[1];
for(u=1;u<=t1;u++)
{
if(sc[u]<min)
min=sc[u];
}
for(u=1;u<=t1;u++)
{
if(sc[u]==min)
count++;
}
if(count>1)
printf(“Polygamy not allowed”);
if(count==1)
{
for(u=1;u<=t1;u++)
{
if(sc[u]==min)
printf(“%d:%d:%d”,x[u],y[u],max);
}
}
}
return
0; }
Result:
72
TASK 12
IMPLEMENT COMMON STYLE TECHNIQUE
1. Ramesh Salary:
2. The Distance :
73
3. Marks:
4. Leap Year:
5. Two numbers are input through the keyboard into two locations C and D.
Write a program to interchange the contents of C and D.
#include<stdio.h>
#include<conio.h>
main()
74
{
int c,d,e;
clrscr();
printf(“\n Enter the number at location C:”);
scanf(“%d”, &c);
printf(“\n Enter the number at location D:”);
scanf(“%d”, &d);
e=c; c=d; d=e;
printf(“\n New Number at location C=%d”,c);
printf(“\n New Number at location D=%d”,d);
printf(“\n\n\n\n\n Press any key to exit….”);
getch();
}
#include <stdio.h>
int addNumbers(int n);
int main() {
int num=20;
printf(“Sum = %d”, addNumbers(num));
return 0; }
int addNumbers(int n) {
if (n != 0)
return n + addNumbers(n – 1);
else
return n;
}
Result:
75
TASK 13
STUDY ON BASIC CONCEPTS OF COMPILE, LINK AND OS
Aim:
To understand and to implement basic concepts behind compiling linking hardware tools
compilation and execution.
Programming tool 1
Turbo C ++
Steps to install
Step 2: If any previous Turbo C++version already installed in your computer then first
uninstall that
Step 6: If you want to run Turbo on full screen simply click on button Run Turbo
Step 7: If you want full screen mode unclick the full screen mode checkbox and click
on button start Turbo
Step 1: Start Turbo C plus plus from start all programs or from desktop
76
NetBeans
Steps to install
Step 1: To use NetBeans for Java programming you need to first install Java
development kit
Step 2: Select file new project from the file menu select project category as C++ and
project type as C++ application from the dialogue that pop up click next button
Step 3: Type a suitable project name in project name textbox click finish
Programming tools 3
Steps to install
Step 6: Visual Studio will start download in the initial files download speed will vary as
per your internet connection
77
Step 8: In the next screen select .net desktop development
Step 10: Download the relevant files based on the selection in step 6
Step 15: In Visual Studio ID you can navigate to file menu to create new C# applications
Step 2: Select file new project from file menu select project type a visual C++ when is
console application from the dialogue that pops up . Type a suitable project name
Programming tools 4
Eclipse
Steps to install
78
Steps to compile and execute
Programming tools 5
Android studio
Steps to install
Step 2: If you download a Zip file unpack the zip copy Android studio folder into your
program files folder
Step 3: Follow the setup Wizard in the Android studio and install any SDK packages
that recommends
Step 1: Creating a new project with support for native code is to creating and other
Studio but there is an additional step
Step 2: In the choose your project section of the wizard select the native C++ project
type
79
Step 4: Complete all other fields in the next section of the wizard.
Step 5: Click next in the customise C++ support section of the wizard you can
customise your project.
Step 6: Click finish after Android studio finish Creating your new project open the
project pad from left side of the IDE and select the Android view.
Result:
80
TASK 14
PRACTICE PROBLEMS FOR CODE IMPLEMENTATION
PRACTICE PROBLEMS
Pseudocode 1:
Code :
int main( )
{ int n, k, f1, f2, f;
if ( n < 2 ) return n;
else { f1 = f2 = 1;
for(k=2;k<n;k++)
{ f = f1 + f2; f2 = f1; f1 = f; }
return f;
}
Pseudocode 2:
Code :
81
Pseudocode 3:
Print "passed"
else
Print "failed"
Pseudocode 4:
Pseudocode 5:
else
82
Pseudocode 6:
else
Result:
Thus, the practice problem for coding preparation for coding preparation is
successfully practiced.
83