#include <stdio.h> #include <stdlib.h> #include <string.h> ///////////////////////////////////////////////////////////////////////////// // INTEGRITY INSTRUCTIONS // Explicitly state the level of collaboration on this question // Examples: // * I discussed ideas with classmate(s) [include name(s)] // * I worked together with classmate(s) in the lab [include name(s)] // * Classmate [include name] helped me debug my code // * I consulted website [include url] // * None // A "None" indicates you completed this question entirely by yourself // (or with assistance from course staff) ///////////////////////////////////////////////////////////////////////////// // INTEGRITY STATEMENT: // I received help from the following sources: // None // Name: Daniel Weintraub // login ID: dweintra ///////////////////////////////////////////////////////////////////////////// #include <assert.h> #include <stdio.h> #include <stdlib.h> /* * node is a node in a linked list */ struct node { int value; struct node *next; }; /* * llist is a linked list */ struct llist { struct node *first; }; void node_destory(struct node* node) { assert(node); free(node); } struct node *node_create(int value) { struct node *new_node = malloc(sizeof(struct node)); new_node->value = value; new_node->next = NULL; return new_node; } struct llist *list_create(void) { struct llist *list = malloc(sizeof(struct llist)); list->first = NULL; return list; } void list_append(struct llist *list, const int value) { assert(list); struct node *new_node = node_create(value); if (list->first == NULL) { // list is empty list->first = new_node; } else { struct node *current = list->first; while (current->next != NULL) { // find last node current = current->next; } current->next = new_node; } } void list_print(const struct llist *list) { assert(list); struct node *current = list->first; if (current == NULL) { // list is empty printf("List empty\n"); } else { int i = 0; while(current != NULL) { // travers nodes printf("Node #%d: %d\n", i++, current->value); current = current->next; } } } void list_destroy(struct llist *list) { assert(list); struct node *current = list->first; while (current != NULL) { // travers nodes struct node *to_free = current; current = current->next; node_destory(to_free); } free(list); } void add_front(int value, struct node** front_node) { struct node* new_node = malloc(sizeof(struct node)); new_node->value = value; new_node->next = *front_node; *front_node = new_node; } void reverse_iter(struct llist *list) { struct llist *lst = list_create(); struct node *node = list->first; while (node) { add_front(node->value,&lst->first); node = node->next; } list_destroy(list); list = lst; list_destroy(lst); } int main(void) { struct llist *list = list_create(); int input; for(int i = 0; i<3; i++){ list_append(list, i); } reverse_iter(list); list_print(list); list_destroy(list); }
#include <stdio.h> int main() { int a, b, c, d; a = 5; b = 3; c = a + b; d = a - b; printf("Sum = %d\n", c); printf("Subtruct = %d\n", d); return 0; }
#include <stdio.h> int main() { int i, j, k, l; float a, b; i = 2; j = 3; k = i/j * j; l = j/i * i; a = i/j * j; b = j/i * i; printf("k = %d\n", k); printf("l = %d\n", l); printf("a = %f\n", a); printf("b = %f\n", b); return 0; }
#include <stdio.h> int main() { int a; int b; int c; a= 50; b=200; c=3; printf("the values of a b c are: %d %d %d\n", a, b, c); if(a>b && a>c) { printf("a is the largest number"); } else { if(b>a && b>c) { printf(" b is the largest number"); } else { printf("c is the largest number"); } } return 0; }
#include <stdio.h> #define max 5 int queue[max]; int f=-1,r=-1; void insert() { int item; if(r==max-1) printf("Queue is full"); else { if(f==-1) f=0; printf("Enter the element to insert into queue:\n"); scanf("%d",&item); r=r+1; queue[r]=item; } } void delete() { if(f==-1 || f>r) printf("Queue is empty...\n"); else { printf("Element deleted from queue is : %d\t",queue[f]); f=f+1; } } void display() { int i; if(f==-1) printf("Queue is empty"); else { printf("Elements in Queue :\n%d"); for(i=f;i<=r;i++) { printf("%d",queue[f]); printf("\n"); } } } int main() { printf("Queue Implementation\n"); printf("Enter your choice:\n1.Insert\n2.Delete\n3.Display\n4.Quit\n"); int choice,n=1; while(n=1) { scanf("%d",&choice); switch(choice) { case 1: insert(); break; case 2: delete(); break; case 3: display(); break; case 4: n=0; break; } } return 0; }
#include <stdio.h> int main () {// short end operators int a = 20; int c; c=a; // c= 20 : direct assignment printf("%d\n", c); c= a++ ; // c= 20 but the a value will be 21: post increment printf("%d\n", c); c = a-- ; // c= 21 but the a value will be 20 :post decrement printf("%d\n",c); c = ++a; // c=21 but the value of a is 21 : pre increment printf("%d\n",c); c= --a; // c=20 but the value of a also is 20 :pre decrement printf("%d\n",c); //once in post methods assignment is over then value of lhs will not change just the present valur of rhs will change. return 0; }
#include <stdio.h> int main() { int arr[14]={10,20,30,10,20,40,20,20,10,30,30,20,50,50}, n=14, count=0, i, j, num=0; num=arr[i]; for(i=1;i<n;i++) { if(num==arr[i]) { count=count+1; } num=arr[i+1]; } printf("The number of pairs are %d\n",(count/2)); return 0; }
#include <stdio.h> #include <stdlib.h> int main() { enum boolean { no, yes}; enum days {sun=1, mon=4, tue, wed, thu=9, fri, sat}; enum names {varun=10, sai=111, immidi, meghana=1, gudreddy}; // user defined data types and each value has been assigned with an integer value starting from 0 and keeps on incrementing by 1 unit. enum names first = immidi; enum boolean flag = no; enum days day = tue; printf("%d %d %d %d", first, flag, day, sat); return 0; }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more