diff --git a/level1/act1.c b/level1/act1.c index e69de29..6dec6e5 100644 --- a/level1/act1.c +++ b/level1/act1.c @@ -0,0 +1,50 @@ +#include + +void inputTemperatures(int n, float temps[n]) +{ + for(int i=0;imax){ + max=temps[i]; + } + } + return max; +} +float findLowest(int n, float temps[n]) +{ + float min=temps[0]; + for(int i=0;i + +struct ElectricityBill{ + int units; + float rate; + float total_bill; +}; + +typedef struct ElectricityBill Ebill; + +Ebill input() +{ + Ebill bill; + printf("Enter number of units consumed: "); + scanf("%d",&bill.units); + printf("Enter rate per unit: "); + scanf("%f",&bill.rate); + return bill; +} + +Ebill calculate_bill(Ebill bill) +{ + bill.total_bill=bill.units*bill.rate; + + if(bill.units>100){ + int extra_units=bill.units-100; + float extra_charge=extra_units*5.0; + } +} diff --git a/level1/demo1.c b/level1/demo1.c index e69de29..bc490a7 100644 --- a/level1/demo1.c +++ b/level1/demo1.c @@ -0,0 +1,39 @@ +#include + +void input(int n, float arr[n]) +{ + for(int i=0;iarr[max_index]){ + max_index=i; + } + } + return max_index; +} + +void output(int max_index, float arr[]) +{ + printf("Maximum value in the array is %.2f at index %d",arr[max_index],max_index); +} + +int main() +{ + int n,max_index; + printf("Enter the value of n:"); + scanf("%d",&n); + float arr[n]; + input(n,arr); + max_index= find_max_index(n,arr); + output(max_index,arr); + return 0; +} \ No newline at end of file diff --git a/level1/demo2.c b/level1/demo2.c index e69de29..1d9cb3b 100644 --- a/level1/demo2.c +++ b/level1/demo2.c @@ -0,0 +1,52 @@ +#include + +struct rectangle{ + char name[50]; + float length; + float width; + float area; +}; + +typedef struct rectangle Rectangle; + +Rectangle input(int rectNum) +{ + Rectangle rect; + printf("Enter the name for the rectangle %d: ",rectNum); + scanf("%s",rect.name); + printf("Enter the length and width of rectangle %s: ",rect.name); + scanf("%f%f",&rect.length,&rect.width); + return rect; +} + +float calculate_area(Rectangle rect) +{ + return(rect.length*rect.width); +} + +void compare_areas(Rectangle r1, Rectangle r2, Rectangle r3) +{ + if(r1.area>r2.area && r1.area>r3.area) + { + printf("Area of rectangle 1 which is %.2f is the largest.",r1.area); + } + else if(r2.area>r3.area) + { + printf("Area of rectangle 2 whcih is %.2f is the largest.",r2.area); + } + else + { + printf("Area of rectangle 3 which is %.2f is the largest.",r3.area); + } +} + +int main() +{ + Rectangle r1=input(1); + Rectangle r2=input(2); + Rectangle r3=input(3); + r1.area=calculate_area(r1); + r2.area=calculate_area(r2); + r3.area=calculate_area(r3); + compare_areas(r1,r2,r3); +} \ No newline at end of file diff --git a/level1/demo3.c b/level1/demo3.c index e69de29..0a10b93 100644 --- a/level1/demo3.c +++ b/level1/demo3.c @@ -0,0 +1,55 @@ +#include + +struct rectangle{ + float length; + float width; + float area; +}; + +typedef struct rectangle Rectangle; + +void input(int n, Rectangle rects[n]) +{ + for(int i=1;i<=n;i++){ + printf("Enter the length and width of Rectangle %d: ",i); + scanf("%f%f",&rects[i].length,&rects[i].width); + } +} + +void calculate_area(int n, Rectangle rects[n]) +{ + for(int i=1;i<=n;i++){ + rects[i].area=rects[i].length*rects[i].width; + } +} + +int find_largest_index(int n, Rectangle rects[n]) +{ + int largest_index=0; + for(int i=1;i<=n;i++){ + if(rects[i].area>rects[largest_index].area){ + largest_index=i; + } + } + return largest_index; +} + +void output(int largest_index, Rectangle rects[]) +{ + printf("The rectangle with the largest area is at index %d with area %.2f",largest_index,rects[largest_index].area); +} + +int main() +{ + int n; + printf("Enter the number of rectangles: "); + scanf("%d",&n); + + Rectangle rects[n]; + input(n,rects); + calculate_area(n,rects); + + int largest_index=find_largest_index(n,rects); + output(largest_index,rects); + return 0; +} \ No newline at end of file diff --git a/level1/demo4.c b/level1/demo4.c index e69de29..94a0797 100644 --- a/level1/demo4.c +++ b/level1/demo4.c @@ -0,0 +1,23 @@ +#include + +struct flight{ + int flight_number; + char destination[20]; + int available_seats; +}; + +typedef struct flight Flight; + +void readFlights(int n, Flight f[]) +{ + for(int i=0;i + +void read_array(int n, int arr[]) +{ + for(int i=0;i