ISTS Pseudo Codes
ISTS Pseudo Codes
1.
#include<stdio.h>
int main ()
{
char c,a,b;
c='f';
a='s';
b='x';
int sum= c+a+b;
printf ("%d", sum);
}
2.
#include<stdio.h>
int func(int a)
{
return a--;
}
int main()
{
int a= func(5);
printf("%d",a++);
return 0;
}
3.
#include<stdio.h>
int main()
{
int val=5;
do{
Val++; #6
++val; #7
}
while(val++>7); #8
printf("%d",val);
return 0;
}
4.
#include<stdio.h>
int main()
{
int m=0;
if(m==0)
{
m=((5,(m=3)),m=1);
printf("%d",m);
}
else
printf("Test");
return 0;
}
5.
#include<stdio.h>
void main()
{
int i=0;
while(*(/—i)!=0)
i=i+4;
printf("%d",i);
}
6.
#include<stdio.h>
void main()
{
int a=8,b=6,c=5;
if(b>a || a>c || c>b)
b++;
else
a=b-–;
printf("%d",a+b+c);
}
7.
#include<stdio.h>
int main( )
{
int n=5, 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;
}
printf("%d",f) ;
}
}
Ans - 5
8.
initialize i,n
initialize an array of size n
accept the values for the array
for i= 0 to n
arr[i] = arr[i]+arr[i+1]
end for
print the array elements
9.
Integer x, y, Z, a
Set x=2,y=1,z=5
a = (x AND y) OR (z + 1)
Print a
Options :
A. 5
B. 3
C. 2
D. 1
10.
C. Code executes successfully and the value of salary is displayed an infinite number of times.
&, |, ^
#include<stdio.h>
int fun(int x, int y);
int main()
{
int i,n;
i=5;
n=7;
int f = fun(5,7);
printf("%d", f);
}
Ans : 2
2.
int main()
{
int array[] = {5, 3, 1, 9, 8, 2, 4, 7};
int size = sizeof(array)/sizeof(array[0]);
int i, j, min_idx,temp;
for (i = 0; i < size-1; i++)
{
min_idx = i;
for (j = i+1; j < size; j++)
{
if (array[j] < array[min_idx])
min_idx = j;
}
temp = array[min_idx];
array[min_idx] = array[i];
array[i] = temp; }
}
#include<stdio.h>
int main()
{
float m=3.0;
switch((int)m)
{
case 1:
printf("ninja");
break;
case 2:
printf("digital");
break;
case 3:
printf("prime");
break;
}
return 0;
}
4.
#include<stdio.h>
int func(int n)
{
int i=0;
while(n%10!=0)
{
n=n+3;
i++;
}
n=n-i;
return n;
}
void main()
{
printf("%d",func(35));
}
a. 50
b. 55
c. 53
d. 45
Ans : 50-5=45
5.
#include <stdio.h>
int main()
{
// a = 5 (00000101), b = 9 (00001001)
unsigned int a = 5, b = 9;
return 0;
}
1.
for i in range(N):
A = a + random()
for i in range(M):
b = b+ random()
Ans
Time - O(N+M)
Space - O(1)
2.
Ans
O(N^2)
End
3.
int i, j, k=0;
for (i=n/2; i<=n; i++)
for (j=2; j<=n; j=j*2)
k = k+n/2;
Ans :
O((n/2)logn) = O(n*logn)
4.
Int a = 0, i = N;
while(i>0) {
a += i;
i /= 2;
}
Ans - O(log(n))
Day - 3
1.
#include <stdio.h>
#include <stdlib.h>
#define LIMIT 10 /*size of integers array*/
int main(){
unsigned long long int i,j;
int *primes;
int z = 1;
primes = malloc(sizeof(int)*LIMIT);
for (i=2;i<LIMIT;i++)
primes[i]=1;
for (i=2;i<LIMIT;i++)
if (primes[i])
for (j=i;i*j<LIMIT;j++)
primes[i*j]=0;
for (i=2;i<LIMIT;i++)
if (primes[i])
// printf("%dth prime = %dn\n",z++,i);
printf("%dth prime = %llun\n",z++,i);
return 0;
Ans
Prime numbers filtering question
1th prime = 2n
2th prime = 3n
3th prime = 5n
4th prime = 7n
End
2.
count = 0
for (int i = N; i > 0; i /= 2)
for (int j = 0; j < i; j++)
count++;
Ans :
O(N)
End
3.
Ans :
Reversing a string
End
Which of the following is not a keyword?
a) Read
b) Write
c) start
d) endif
The statement that tells the computer to get a value from an input device and store it in a memory location.
a) read
b) write
c) READ
d) WRITE
_____________ are identified by their addresses, we give them names (field names / variable names) using
words.
a) Memory variables
b) Memory Locations
c) Memory Addresses
d) Data variables
a) Adding complexity
b) Enhancing readability
c) Creating graphics
d) Formatting output
How does pseudo-code contribute to the debugging process?
1.
{
int a = x + y + z;
return (a);
}
2.
//Sum Of N Natural Number
int sum(int n)
{
int i,sum=0;
for(i=n;i>=1;i--)
sum=sum+i
return sum;
}
3.
factorial(N){
if(N<=1)
{
return 1;
}
else
{
return (N*factorial(N-1));
}
}
4.
Initialize i, n
Set arr[]= 1, 2, 3, 4, 5
for i = 0 to n - 2
arr[i] = arr[i] + arr[i+1]
End for
Ans
3, 5, 7, 9, 5
End
5.
Integer x, y, z
Set x = 0, y = 3, z = 11
if(x + (1 | 2) && y + (2 | 3))
x=x-2
y=x
Else
x=z
y=y^2
End if
Print x + y + z
Ans
7
End
2, 4
Integer solve(Integer x, Integer y)
if(y > 0)
if(x > 0)
return x + y + solve(2, y - 5) + solve(x - 10, 1)
End if
End if
return x + y
End function solve()
Ans
18
End
12345
Initialize i, n
Initialize an array of size n
Take the values for the array
for i = 0 to n - 2
arr[i] = arr[i] - arr[i+1]
End for
Ans
11111
End
N = -5 , m = -2
Integer solve(Integer n, Integer m )
if(n > 4 && m < 7)
return solve(n +1, m + 1)
Else
Return n + m
End if
End function solve()
Ans
13
End
6.
Integer x, y, z
Set x = 10, y = 16,z = 3
if(x > y)
x=2*y
Else
y=x/2
End if
if(z > y)
z=2*y
Else
y=z/2
End if
Print x + y + z
Ans
14
End
7.
Integer w, x, y, z
Set w = 21, x = 11
for (each y from 21 to 30 )
for (each z from -1 to 0 )
w=w-1
if(w > y)
Continue
End if
w=1
if(w > z)
Jump out of the loop
End if
End for
End for
Print w + x
Ans
12
End
8.
Integer x, y, z
Set x = -2, y = 3, z = 1
if(x + (2 & 2) && y + (3 & 3) && z + (2 ^ 2))
x=x-2
y=x
Else
x=z
y=y^2
End if
Print x+ y+ z
Ans
3
End
9.
X = 9 y= 7
Integer funn(Integer x, Integer y)
Integer z
Set z = 2
y = y mod z
x = x mod z
return x + y
End function funn()
Time complexity of fibonacci program :
def f(n):
if n == 0 or n == 1:
return 1
return f(n - 1) + f(n - 2)
def fun(n,m):
arr=[[0]*m for i in range(n)]
for i in range(n):
for j in range(m):
k=1
while k<n*m:
k*=2
Ans
Time complexity : O(n*m* log (n*m))
Space complexity: O(n*m)
End