C program LAB REPORT (1)
C program LAB REPORT (1)
Write a program to find the average expenditure of a company for each month of each
year, each year and average over the range of years specified. Use arrays to construct a
table, display the table of expenditure and find the sum and average.
#include <stdio.h>
int main() {
scanf("%d", &years);
scanf("%d", &startYear);
scanf("%f", &expenditure[i][j]);
printf("\nYear\tTotal\t\tAverage\n");
yearlyTotal = 0.0;
yearlyTotal += expenditure[i][j];
}
float yearlyAverage = yearlyTotal / 12.0;
overallTotal += yearlyTotal;
return 0;
2. Write a program to find the position of the character 'C' in the sentence "idea without
execution is worthless" using pointer and string.
#include <stdio.h>
int main() {
3. Store and retrieve the name of the students and obtained marks in c programming in
1st semester using structure.
#include <stdio.h>
struct Student {
char name[50];
float marks;
};
int main() {
int n;
scanf("%d", &n);
scanf("%f", &students[i].marks);
printf("Name\t\tMarks\n");
return 0;
4. Write a program to read name, rollno, address, and phone number of each student in
your class using structure. Store the information in file so that you can recover the
information later. While recovering the information from the file sort the information
alphabetically according to the name.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
char name[50];
int rollno;
char address[100];
char phone[10];
};
temp = s[i];
s[i] = s[j];
s[j] = temp;
int main() {
int n;
FILE *fp;
scanf("%d", &n);
printf("Name: ");
scanf("%d", &students[i].rollno);
printf("Address: ");
fp = fopen("students.txt", "w");
if (fp == NULL) {
return 1;
fprintf(fp, "%s\n%d\n%s\n%s\n",
students[i].name,
students[i].rollno,
students[i].address,
students[i].phone);
fclose(fp);
fp = fopen("students.txt", "r");
if (fp == NULL) {
return 1;
}
int count = 0;
count++;
fclose(fp);
sortByName(loaded, count);
}
return 0;