Write a C program to convert a 23.65 into 25 using pointer
- Declare a double variable to hold the floating-point number (23.65).
- Declare a pointer to double to point to the address of the variable.
- Use the pointer to modify the value to 25.0.
- Print the modified value.
#include <stdio.h>
int main() {
double num = 23.65;
double *ptr;
ptr = #
*ptr = 25.0;
printf("Modified value: %.2f\n", num);
return 0;
}
Thus the program to convert a 23.65 into 25 using pointer has been executed successfully.
Write a C program to calculate the Product of first 12 natural numbers using Recursion
- Define a recursive function calculateProduct that takes an integer parameter n.
- Return n multiplied by the result of the calculateProduct function called with n - 1.
- Declare an integer variable n and an unsigned long long variable product.
- Initialize n with the value 12 (for the first 12 natural numbers).
- Call the calculateProduct function with n and store the result in the product variable.
- Print the result, indicating it is the product of the first 12 natural numbers.
#include <stdio.h>
unsigned long long calculateProduct(int n) {
if (n == 1)
return 1;
else
return n * calculateProduct(n - 1);
}
int main() {
int n = 12;
unsigned long long product;
product = calculateProduct(n);
printf("The product of the first 12 natural numbers is: %llu\n", product);
return 0;
}
Thus the program has been executed successfully.
Write C Program to find Sum of each row of a Matrix
- Declare and initialize the matrix with the desired values.
- Create a loop to iterate through each row of the matrix.
- Inside the loop, calculate the sum of the elements in each row.
- Print the sum for each row.
#include <stdio.h>
int main() {
int rows, cols, i, j, sum;
int matrix[10][10];
printf("Enter number of rows: ");
scanf("%d", &rows);
printf("Enter number of columns: ");
scanf("%d", &cols);
printf("Enter elements of the matrix:\n");
for(i = 0; i < rows; i++) {
for(j = 0; j < cols; j++) {
scanf("%d", &matrix[i][j]);
}
}
for(i = 0; i < rows; i++) {
sum = 0;
for(j = 0; j < cols; j++) {
sum += matrix[i][j];
}
printf("Sum of row %d = %d\n", i + 1, sum);
}
return 0;
}
Thus the program has been executed successfully.
Write C program for the below pyramid string pattern. Enter a string: PROGRAM Enter number of rows: 5 P R O G R A M P R O G R A M P R O G R A M
- Input the number of rows for the pyramid (e.g., num_rows).
- Initialize variables:i for the row count (starting from 1),j for the character count (starting from 1)
- Start a loop for i from 1 to num_rows (for each row of the pyramid).
- Calculate the midpoint position as midpoint = (2 * num_rows - 1) / 2.
- End the program.
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
int rows;
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
str[strcspn(str, "\n")] = '\0';
printf("Enter number of rows: ");
scanf("%d", &rows);
int length = strlen(str);
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= rows - i; j++)
{
printf(" ");
}
for (int j = 0; j < i; j++)
{
printf("%c ", str[j % length]);
}
printf("\n");
}
return 0;
}
Thus the C program to String process executed successfully
.
Write a c program to read and display an array of any 6 integer elements using pointer
Step 1: Start the program. Step 2: Declare the following: • Integer variable i for iteration. • Integer variable n to store the number of elements. • Integer array arr[10] to hold up to 10 elements. • Integer pointer parr and initialize it to point to the array arr. Step 3: Read the value of n (number of elements) from the user. Step 4: Loop from i = 0 to i < n: • Read an integer value and store it in the address parr + i using pointer arithmetic. Step 5: Loop from i = 0 to i < n: • Print the element at *(parr + i) using pointer dereferencing. Step 6: End the program.
#include <stdio.h>
int main() {
int i, n;
int arr[10];
int *parr = arr;
printf("Enter number of elements (max 10): ");
scanf("%d", &n);
printf("Enter %d elements:\n", n);
for(i = 0; i < n; i++) {
scanf("%d", (parr + i));
}
printf("The array elements are:\n");
for(i = 0; i < n; i++) {
printf("%d ", *(parr + i));
}
return 0;
}
Thus the C program to read and display an array of any 6 integer elements using pointer has been executed




