Pci Question Bank Ct2
Pci Question Bank Ct2
int main()
{
int number, reverse;
reverse = findReverse(number);
return 0;
}
Output:
Enter a positive integer: 325
The reverse of 325 is: 523
2. State 4 arithmetic operations to perform on pointer with example.
Ans: 1. Increment: ++pointername
Input:
#include <stdio.h>
#include <conio.h>
int main()
{
int a = 4, b = 5;
int *ptr1 = &a;
int *ptr2 = &b;
printf("Value of ptr1 is %d\n", ptr1);
printf("Value of ptr1 after increment is %d", ++ptr1);
return 0;
}
Output:
Value of ptr1 is 6487564
Value of ptr1 after increment is 6487568
2. Decrement: --pointername
Input:
#include <stdio.h>
#include <conio.h>
int main()
{
int a = 4, b = 5;
int *ptr1 = &a;
int *ptr2 = &b;
printf("Value of ptr1 is %d\n", ptr1);
printf("Value of ptr1 after decrement is %d", --ptr1);
return 0;
}
Output:
Value of ptr1 is 6487564
Value of ptr1 after decrement is 6487560
3. Addition: *ptr1 + *ptr2
Input:
#include <stdio.h>
#include <conio.h>
int main()
{
int a = 4, b = 5;
int *ptr1 = &a;
int *ptr2 = &b;
printf("Value of a + b is %d", *ptr1 + *ptr2);
return 0;
}
Output:
Value of a + b is 9
int factorial(int);
int main()
{
int num, fact;
printf("Enter number: ");
scanf("%d", &num);
fact = factorial(num);
printf("Factorial of %d is %d", num, fact);
return 0;
}
int factorial(int x)
{
int fact;
if(x == 1)
{
return 1;
}
else{
fact = x * (x-1);
return fact;
}
}
Output:
Enter number: 6
Factorial of 6 is 30
9. Write a program to add, subtract, multiply and divide two integers
using functions.
Ans: Program:
#include <stdio.h>
#include <conio.h>
int main()
{
int num1, num2, sum, subtract, multiply, divide;
printf("Enter value of first number: ");
scanf("%d", &num1);
printf("Enter value of second number: ");
scanf("%d", &num2);
sum = addition(num1, num2);
printf("Addition of %d and %d is %d\n", num1, num2, sum);
subtract = substraction(num1, num2);
printf("Substraction of %d and %d is %d\n", num1, num2, subtract);
multiply = multiplication(num1, num2);
printf("Multiplication of %d and %d is %d\n", num1, num2, multiply);
divide = division(num1, num2);
printf("division of %d and %d is %d\n", num1, num2, divide);
return 0;
}
Output:
Enter value of first number: 40
Enter value of second number: 20
Addition of 40 and 20 is 60
Subtraction of 40 and 20 is 20
Multiplication of 40 and 20 is 800
division of 40 and 20 is 2
10. Write a program to read two strings and find whether they are equal
or not.
Ans: Program:
#include <stdio.h>
#include <conio.h>
int main()
{
int result;
char string1[] = "India";
char string2[] = "India";
return 0;
}
Output:
Both the strings are equal