[go: up one dir, main page]

0% found this document useful (0 votes)
58 views10 pages

Accenture Sample Pseudo Code Questions

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 10

Practice from Accenture Sample Pseudo Code

Questions
1. What will be the output of the following pseudo code?
For input a = 5 & b = 5.
function (input a, input b)
If (a < b)
return function (b, a)
elseif (b != 0)
return (a * function (a, b - 1))
else
return 0

15625

625

3125

525

2. What will be the output of the following pseudo code

initialize char c
set c= a
print "%d",a

64

97

error

3. What will be the output of the following code ?

#include<stdio.h>
int main ()
{
char c,a,b;
c='f';
a='s';
b='x';
int sum= c+a+b;
printf ("%d", sum);
}

324

315
320

337

4. What will be the output of the following pseudo code for arr[]= 1,2,3,4,5

initialize i,n
intialize 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

35795

3 5 7 9 11

3 5 9 15 20

error

5. What will be the output of the following pseudo code ?

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

int fun(int x, int y)


{
if(x<=0)
return y;
else
return(fun(x-1,y-1));
}

0(zero)

3
6. What will be the output of the following code

#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);
return 0;

None of the below

1th prime - 2n
2th prime - 3n
3th prime - 5n

1th prime - 2n
2th prime - 3n
3th prime - 5n
4th prime - 7n
5th prime - 9n
6th prime - 11n

1th prime - 2n
2th prime - 3n
3th prime - 5n
4th prime - 7n

7. What will be the output of the following code snippet?

#include <stdio.h>
#include <stdlib.h>int main(){
int m = 2, c=1;
int n,a,b, limit=10;
while(c < limit)
{
for (int n = 1; n < m; ++n)
{
a = m * m - n * n;
b = 2 * m * n;
c = m * m + n * n;
if (c > limit)
break;
printf("%d %d %d\n", a, b, c);
}
m++;
}
}

157

257
7 9 10

123
456
789

345
8 6 10

8. What will be the output of the following Code ?

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

13

7
9. What purporse does the following code serves

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

Finds some specific element in the array

Sort the elements of array

Find the smallest element in the array

None of the above

10. What operation does the following pseudo code performs

Declare an array of string type variable called word


Declare a loopcounter
Store a string in the array word
for loopcounter = (length of the word) – 1 to 0
loopcounter = loopcounter – 1
print arrayword[loopcounter]
endfor
Algorithm end

It accepts a string

It reverses the string

It prints the string in the same order

none of the above

11. What will be the output of the following pseudocode?

#include<stdio.h>
int func(int a)
{
return a--;
}
int main()
{
int a= func(5);
printf("%d",a++);
return 0;
}

12. What will be the output of the following pseudocode?

#include<stdio.h>

int main()
{
float m=3.0;
switch((int)m)
{
case 1:
printf("Prepinsta");
break;
case 2:
printf("Prime");
break;
case 3:
printf("Prepinsta Prime");
break;
}
return 0;
}

PrepInsta

Prime

Prepinsta

error

13. What will be the output of the following pseudo code?

#include

#include<stdio.h>
int main()
{
int val=5;
do{
val++;
++val;
}while(val++>7);
printf("%d",val);
return 0;
}

11

10

14. What will be the output of the following pseudocode?

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

Test

15. What will be the output of the following pseudo code?

#include<stdio.h>

void fun1(char *s1, char *s2) {


char *tmp;
tmp = s1;
s1 = s2;
s2 = tmp;
}
void fun2(char **s1, char **s2) {
char *tmp;
tmp = *s1;
*s1 = *s2;
*s2 = tmp;
}

int main () {
char *str1 = "Prepinsta", *str2 = "Prime";
fun1(str1, str2); printf("%s %s ", str1, str2);
fun2(&str1, &str2); printf("%s %s ", str1, str2);
return 0;
}

Prepinsta Prime Prime Prepinsta

Prime Prepinsta Prime Prepinsta

Prime Prepinsta Prepinsta Prime

Prepinsta Prime Prepinsta Prime

16. What will be the output of the following pseudo code ?

#include<stdio.h>
void main()
{
int i=0;
while(+(+i--)!=0)
i=i+5;
printf("%d",i);
}

-1

-2

17. What will be the output of the following pseudo code ?

#include<stdio.h>
int main()
{
char c= 'Z';
printf(“%d”,c);
}

'Z'
90

122

18. What will be the output of the following pseudo code ?

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

50

55

53

45

19. What will be the output of the following pseudo code ?

#include<stdio.h>
int func(int no)
{
static int count=0;
count=count+no;
return count;
}
void main()
{
int i,j;
for(i=0;i<=5;i++)
j=func(i);
printf("%d",j);
}

18

15
20

25

20. What will be the output of the following pseudo code ?

#include<stdio.h>

void main()
{
int a=5,b=2,c=1;
if(b>a && a>c && c>b)
b=a+1;
else
a=b+1;
printf("%d",a+b+c);
}

11

19

You might also like