Aptitude Lab Practical File

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Q.

1 Find the output of c programming printf based


aptitude question?

#include<stdio.h>
// sum of 2 number
int main() {
int a, b;
printf("enter a \n");
scanf("%d", &a);
printf("enter b \n");
scanf("%d", &b);
printf("sum of a & b is : %d \n", a+b);
return 0;
}
output-
a=5
b=4
Value is = 9
Q.2- Find the output of c programming using with operators?
#include<stdio.h>
Int main()
{
//working of arithmetic operators.
int a=9, b=4, c;
c=a+b;
printf(“a+b = %d \n”, c);
c=a-b;
printf(“a-b = %d \n”, c);
c=a*b;
printf(“a*b = %d \n”, c);
c=a/b;
printf(“a*b = %d \n”, c);
c=a%b
printf(“a%b = %d \n”, c);
return 0;
}
output
a+b=13 ,
a-b=5
a*b= 36
a/b=2
(Reminder when a divided by b=1)
Q.3- Arrange the operators according to their
precedence: +, %, ->, =.

#include <stdio.h>
int main() {
// according to precedence rule
int a=20;
int b=10;
int c=15;
int d=5;
int e;
e=(a+b)*c/d;
printf("value of (a+b)*c/d is : %d \n",e);
return 0;
}
Output
Value of (a+b)*c/d is : 90
Q.4- Predict the output of following program using with
bitwise?
#include <stdio.h>
int main()
{
int a=12, b=25;
printf("outpur=%d",a&b);

return 0;
}
Operator Meaning of operator
&& Bitwise AND
|| Bitwise OR
! Bitwise NOT
Q.5- Find the output of c programming using with basic
input, output?
Scanf()- The scanf() method in c reads the value from the
console as per the type specified.
Printf()- The printf(() method in c print the value passed as
The parameter to it on the console screen.

# include<stdio.h>
// area of squre
Int main () {
printf(“enter radius”);
scanf(“%f”, & radius);
printf(“area is : %f”, 3.14*radius*radius);
Output
Enter radius : 3
Area is : 28.26
Q.6 Find the output of c programming using with declaration
Data types.
Ans- Data type is a type of data which is used in the program.
In other word use can say that it is used to declare a
Variable.

DATA TYPE

Size Range
Int(2 byte) (-32768 to 32767) Array

char(1 byte) (-128 to 127) Pointer

float(4 byte) (3.4e^-38 to 3.4e^38) Structure

void (no size) Union


Q.7- Which statement does not require semicolon?

Ans- All c program have to follow a basic structure. C


program starts with a function and excites instruction
presents inside it. Each instruction is terminated with a
semicolon (;).
There are some rules which are applicable to all the c
program:
1. Every program execution starts from main () function.
2. All the statement are terminated with a semicolon.
3. Instruction are case-sensitive.
4. Instruction are executed in the same order in which they
are written.
Q8. Dry run program of Declaration and
Initialization Aptitude Questions?

int main (){


int m=10;
int x=printf(“%d”,m);
printf(“%d”,x);
return 0;
}
Output
103
Note:=printf() returns total number of printed characters, the
statement int x=printf("%d ",m) will print 10 (10 and one space) and
return 3. Thus output will be 10 3 [10<space>3].
Q.9:- Find the output of the pseudo code through
Dry run.
The pseudo code in C is an informal way of writing a
program for better human understanding. It written in
simple English, making the complex program easier to
understand.
Pseudo code can’t be compiled or interpreted. It doesn’t
follow the programming language’s syntax, it is thus
written in pseudo code so that any programmers or non-
programmers can easily understand it.
Consider the following source code example:
int n = 10
for (i=0;<n;j++)
printf(n)
The above source code is converted into a pseudo-code
to
Understand in a better way.
The value ten is assigned to the variable n.
For value zero to less than a number.
Display the number.
Q.10- Find the error of pseudo code through dry
run.
#include<stdio.h>
Void main()__
int n, sum=0, i;
printf(“enter the number of item of terms:”);
scanf(“%d”,&n);
for(i=1;i<=n;i+__)
{
sum=sum+i__
}
Print(“sum of series=%d”,sum);
output
Enter the number of terms:5
Sum of sense =1
Error:

You might also like