Write a program to open a file using fopen()
#include<stdio.h> void main() { fopen() file *fp; fp=fopen(“student.DAT”, “r”); if(fp==NULL) { printf(“The file could not be open”); exit(0); }
#include<stdio.h> void main() { fopen() file *fp; fp=fopen(“student.DAT”, “r”); if(fp==NULL) { printf(“The file could not be open”); exit(0); }
#include<stdio.h> int main() { int n, i, max, position; // Ask user for the number of elements printf(“Enter the number of elements: “); scanf(“%d”, &n); int arr[n]; // Input array elements printf(“Enter %d numbers:\n”, n); for (i = 0; i < n; i++) { scanf(“%d”, &arr[i]); } // Initialize max and position max = arr[0]; […]
#include <stdio.h> // Function prototype void displayAges(int ages[], int size); int main() { int ages[5]; // Array to hold ages int i; // Input ages printf(“Enter the age of 5 persons:\n”); for (i = 0; i < 5; i++) { printf(“Person %d: “, i + 1); scanf(“%d”, &ages[i]); } // Call the function and pass […]
#include <stdio.h> int main() { int a[10][10], b[10][10], result[10][10]; int i, j, k, r1, c1, r2, c2; // Input rows and columns for first matrix printf(“Enter rows and columns for first matrix: “); scanf(“%d %d”, &r1, &c1); // Input rows and columns for second matrix printf(“Enter rows and columns for second matrix: “); scanf(“%d %d”, […]
#include <stdio.h> int main() { int arr[100], n, i, j, temp; // Accept total number of elements printf(“Enter the number of elements: “); scanf(“%d”, &n); // Accept array elements printf(“Enter %d numbers:\n”, n); for (i = 0; i < n; i++) { scanf(“%d”, &arr[i]); } // Sort using Bubble Sort for (i = 0; i […]
#include <stdio.h> int main() { int arr[100], n, i; // Accept number of elements printf(“Enter the number of elements: “); scanf(“%d”, &n); // Accept array elements printf(“Enter %d elements:\n”, n); for (i = 0; i < n; i++) { scanf(“%d”, &arr[i]); } // Print alternate elements (0th, 2nd, 4th, …) printf(“Alternate elements in the array:\n”); […]
#include <stdio.h> int main() { int arr[100], n, i; // Input number of elements printf(“Enter the number of elements in the array: “); scanf(“%d”, &n); // Input array elements printf(“Enter %d elements:\n”, n); for (i = 0; i < n; i++) { scanf(“%d”, &arr[i]); } // Increment each element by 1 for (i = 0; […]
The Fibonacci series is a sequence of integers in which the first two integers are 1 and from third integer onwards each integer is the sum of the previous two integers of the sequence i.e. 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ………………………….. The program which implements the above logic is […]
The GCD or HCF (Highest Common Factor) of two integers is the greatest integer that divides both the integers with remainder equals to zero. This can be illustrated by Euclid’s remainder Algorithm which states that GCD of two numbers say x and y i.e. GCD(x, y) = x if y is 0 = GCD(y, x%y) […]