Epshita Moitra
Epshita Moitra
Epshita Moitra
TECHNOLOGY
FYCYS292
1. Create an array of size 10 such that 0-th element of that array contains the value 1, 1st
element contains the value 2, 2nd element contains the value 3 and so on. Display the
array. Do not initialize the array and do not use any scanf function.
Answer:
#include <stdio.h>
int main() {
int array[10];
return 0;
}
OUTPUT:
Array elements:
1 2 3 4 5 6 7 8 9 10
2. Five numbers are entered through the keyboard into an array. Write a C program to
print the square values of them.
Answer:
#include <stdio.h>
int main() {
int numbers[5];
int i;
// Input
printf("Enter five numbers:\n");
for (i = 0; i < 5; i++) {
scanf("%d", &numbers[i]);
}
return 0;
}
OUTPUT:
Enter five numbers:
12345
Square values:
1 4 9 16 25
3. Write a C program to find the largest number of an array of n numbers.
ANSWER:
#include <stdio.h>
int main() {
int n;
return 0;
}
OUTPUT:
Enter the size of the array: 6
Enter 6 numbers:
12
23
45
78
87
90
The largest number is: 90
ANSWER:
#include <stdio.h>
int main() {
int n;
return 0;
}
OUTPUT:
Enter the size of the array: 5
Enter 5 numbers:
12
67
0
65
34
The largest number is: 67
The smallest number is: 0
5. Write a C program to find the total number of even numbers and total numbers
of odd numbers in an array of n numbers.
ANSWER:
#include <stdio.h>
int main() {
int n;
return 0;
}
OUTPUT:
Enter the size of the array: 5
Enter 5 numbers:
123
1
65
70
34
Total number of even numbers: 3
Total number of odd numbers: 2
return 0;
}
OUTPUT:
Enter the size of the array: 5
Enter 5 numbers:
5
4
7
8
9
The sum of the numbers is: 33
7. Write a C program to search whether an element is present or not within an
integer array of size n. Print the position of the key value if it is a successful
search.
ANSWER:
#include <stdio.h>
int main() {
int n, key, found = 0;
return 0;
}
OUTPUT:
Enter the size of the array: 5
Enter 5 numbers:
78
90
12
13
45
Enter the value to search: 12
Element found at position: 3
int main() {
int n;
return 0;
}
OUTPUT:
Enter the size of the array: 6
Enter 6 numbers:
34
67
90
87
54
21
Sorted array in ascending order: 21 34 54 67 87 90
int main() {
int n;
return 0;
}
OUTPUT:
Enter the size of the array: 5
Enter 5 numbers:
12
34
56
78
90
Reversed array: 90 78 56 34 12
10. Write a C program to convert a positive decimal integer to its equivalent binary.
ANSWER:
#include <stdio.h>
void decimalToBinary(int n) {
if (n == 0) {
printf("Binary equivalent: 0\n");
return;
}
while (n > 0) {
binary[i] = n % 2;
n /= 2;
i++;
}
int main() {
int decimal;
if (decimal < 0) {
printf("Please enter a positive decimal integer.\n");
return 1; // Exit with error code 1
}
decimalToBinary(decimal);
return 0;
}
OUTPUT:
Enter a positive decimal integer: 67.8
Binary equivalent: 1000011
11. Write a C program to add two arrays containing 5 elements each and store the
result in a third array.
ANSWER:
#include <stdio.h>
#define SIZE 5
int main() {
int array1[SIZE], array2[SIZE], result[SIZE];
// Add arrays
addArrays(array1, array2, result);
return 0;
}
OUTPUT:
Enter 5 elements for the first array:
34
23
56
67
89
Enter 5 elements for the second array:
56
65
43
123
4
Result array after addition:
90 88 99 79 93