Accenture Sample Pseudo Code Questions
Accenture Sample Pseudo Code Questions
Accenture Sample Pseudo Code Questions
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
initialize char c
set c= a
print "%d",a
64
97
error
#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
#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);
}
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;
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
#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
#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; }
}
It accepts a string
#include<stdio.h>
int func(int a)
{
return a--;
}
int main()
{
int a= func(5);
printf("%d",a++);
return 0;
}
#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
#include
#include<stdio.h>
int main()
{
int val=5;
do{
val++;
++val;
}while(val++>7);
printf("%d",val);
return 0;
}
11
10
#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
#include<stdio.h>
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;
}
#include<stdio.h>
void main()
{
int i=0;
while(+(+i--)!=0)
i=i+5;
printf("%d",i);
}
-1
-2
#include<stdio.h>
int main()
{
char c= 'Z';
printf(“%d”,c);
}
'Z'
90
122
#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
#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
#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