diff --git a/prog1/prog1.c b/prog1/prog1.c index e69de29..8c62691 100644 --- a/prog1/prog1.c +++ b/prog1/prog1.c @@ -0,0 +1,123 @@ +#include + +typedef struct{ + int SRN; + char name[50]; + float marks; +}Student; + +void storeRecords(int n); +void mthRecord(int m); +void deleteRecord(int SRN); + +int main() { + int n, m, SRN; + + printf("Enter number of records:\n"); + scanf("%d", &n); + + storeRecords(n); + + printf("\nEnter mth record to display:\n"); + scanf("%d", &m); + + mthRecord(m); + + printf("\nEnter SRN to delete:"); + scanf("%d", &SRN); + + deleteRecord(SRN); + return 0; +} + +void storeRecords(int n){ + FILE* fp; + Student s; + fp = fopen("recoders.bin", "wb"); + + if(fp == NULL){ + printf("Error opening file\n"); + return; + } + + for(int i = 0; i + +typedef struct{ + int SRN; + char name[50]; + float marks; +}Student; + +void records(Student s[], int n); +int createseekpositions(int pos[], int maxrecords); +void displayrecords(int position); + +int main() { + int n, choice; + int positions[100]; + + printf("Enter number of records:"); + scanf("%d", &n); + + Student s[n]; + + for(int i=0; i= 1 && choice <= total){ + displayrecords(positions[choice - 1]); + }else{ + printf("\nInvalid record number"); + } + return 0; +} + +void records(Student s[], int n){ + FILE *fp; + fp = fopen("records.txt", "w"); + + if(fp == NULL){ + printf("Error opening file\n"); + return; + } + + for(int i=0; i + +void printbits(int num); +int countsetbits(int num); + + +int main() { + int n; + printf("Enter an integer: "); + scanf("%d", &n); + + printf("\nBinary Representation: "); + printbits(n); + + printf("\nNumber of 1 bits = %d\n", countsetbits(n)); + + return 0; +} + +void printbits(int num){ + int totalbits = sizeof(int) * 8; + for(int i=totalbits -1; i>=0; i--){ + int bit = (num >> i)&1; + printf("%d", bit); + + } + printf("\n"); +} + +int countsetbits(int num){ + int count = 0; + while(num!=0){ + if((num&1)==1) + count++; + + num = num>>1; + } + + + return count; +} \ No newline at end of file diff --git a/prog3/prog3.exe b/prog3/prog3.exe new file mode 100644 index 0000000..67f4c41 Binary files /dev/null and b/prog3/prog3.exe differ diff --git a/prog4/prog4.c b/prog4/prog4.c index e69de29..acac45b 100644 --- a/prog4/prog4.c +++ b/prog4/prog4.c @@ -0,0 +1,25 @@ +#include + +struct Bitfield{ + unsigned int firstbit:1; + unsigned int secondbit:2; + unsigned int thirdbit:3; +}; + +int main() { + struct Bitfield a; + + a.firstbit = 1; + a.secondbit = 2; + a.thirdbit = 3; + + printf("firstbit:%u\n", a.firstbit); + printf("secondbit:%u\n", a.secondbit); + printf("thirdbit:%u\n", a.thirdbit); + + a.firstbit = 3; + + printf("\nAfter Assigning 3 to firstbit: \n"); + printf("firstbit = %u\n", a.firstbit); + return 0; +} \ No newline at end of file diff --git a/prog4/prog4.exe b/prog4/prog4.exe new file mode 100644 index 0000000..956aa0d Binary files /dev/null and b/prog4/prog4.exe differ diff --git a/prog5/prog5.c b/prog5/prog5.c index e69de29..055c199 100644 --- a/prog5/prog5.c +++ b/prog5/prog5.c @@ -0,0 +1,99 @@ +#include + + +struct field{ + unsigned int your_choice:1; + unsigned int your_mothers_choice:1; + unsigned int your_fathers_choice:1; + unsigned int socially_acceptable:1; + unsigned int financially_viable:1; + unsigned int do_you_aptitude:1; + unsigned int do_you_likeit:1; + unsigned int decision:1; +}; + +union decision{ + unsigned char flags; + struct field bits; +}; + +union decision input(); +void make_decision(union decision *d); +void print_decision(union decision d); +void print_conclusion_based_on_flags(union decision d); + +int main() { + union decision d; + d = input(); + make_decision(&d); + print_decision(d); + print_conclusion_based_on_flags(d); + return 0; +} + +union decision input(){ + union decision d; + int temp; + d.flags = 0; + + printf("0 ---> NO , 1 ---> YES\n"); + printf("\nEnter your choice(0/1): "); + scanf("%d", &temp); + d.bits.your_choice = temp; + + printf("Enter your mothers choice(0/1): "); + scanf("%d", &temp); + d.bits.your_mothers_choice = temp; + + printf("Enter your fathers choice(0/1): "); + scanf("%d", &temp); + d.bits.your_fathers_choice = temp; + + printf("Is it socially acceptable(0/1): "); + scanf("%d", &temp); + d.bits.socially_acceptable = temp; + + printf("Is it financially viable(0/1): "); + scanf("%d", &temp); + d.bits.financially_viable = temp; + + printf("do you have aptitude for it(0/1): "); + scanf("%d", &temp); + d.bits.do_you_aptitude = temp; + + printf("do you like it(0/1): "); + scanf("%d", &temp); + d.bits.do_you_likeit = temp; + + return d; +} + +void make_decision(union decision *d){ + d -> bits.decision = ( + d -> bits.do_you_likeit && + d -> bits.do_you_aptitude && + d -> bits.financially_viable && + ( + d -> bits.your_mothers_choice || + d -> bits.your_fathers_choice + ) + ); +} + +void print_decision(union decision d){ + printf("\nYour choice: %s\n", d.bits.your_choice ? "YES" : "NO"); + printf("Your mother choice: %s\n", d.bits.your_mothers_choice ? "YES":"NO"); + printf("Your father choice: %s\n", d.bits.your_fathers_choice ? "YEs":"NO"); + printf("Socially acceptable: %s\n", d.bits.socially_acceptable ? "YES":"NO"); + printf("Financially viable:%s\n", d.bits.financially_viable ? "YES":"NO"); + printf("Aptitude: %s\n", d.bits.do_you_aptitude ? "YES":"NO"); + printf("Do you like it: %s\n", d.bits.do_you_likeit ? "YES":"NO"); + printf("Final decision: %s\n", d.bits.decision ? "YES":"NO"); +} + +void print_conclusion_based_on_flags(union decision d){ + if(d.bits.decision) + printf("\nYou should go ahead with your decision"); + else + printf("\nYou should reconsider your decision"); +} \ No newline at end of file diff --git a/prog5/prog5.exe b/prog5/prog5.exe new file mode 100644 index 0000000..90ccc93 Binary files /dev/null and b/prog5/prog5.exe differ diff --git a/prog6/prog6.c b/prog6/prog6.c index e69de29..3908cd6 100644 --- a/prog6/prog6.c +++ b/prog6/prog6.c @@ -0,0 +1,70 @@ +#include +#include + +typedef struct{ + int center_x; + int center_y; + int radius; +}circle; + +void initialize_buffer(int height, int width, char buffer[height][width]); +void draw_circle(int height, int width, char buffer[height][width], circle c); +void print_buffer(int height, int width, char buffer[height][width]); +float calculate_distance(int x1, int x2, int y1, int y2); + +int main() { + int width, height; + printf("Enter circle width: "); + scanf("%d", &width); + + printf("Enter circle height: "); + scanf("%d", &height); + + char buffer[height][width]; + + circle c; + + c.center_x = width/2; + c.center_y = height/2; + + printf("Enter radius: "); + scanf("%d", &c.radius); + + initialize_buffer(height, width, buffer); + draw_circle(height, width, buffer, c); + print_buffer(height, width, buffer); + + return 0; +} + +void initialize_buffer(int height, int width, char buffer[height][width]){ + for(int i=0; i= c.radius - 0.5 && distance <= c.radius + 0.5) + buffer[y][x] = '*'; + } + } +} + +void print_buffer(int height, int width, char buffer[height][width]){ + for(int i=0; i