Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- typedef struct date
- {
- // DO NOT MAKE ANY CHANGE HERE
- int day;
- int month;
- int year;
- } DATE;
- typedef struct person
- {
- // DO NOT MAKE ANY CHANGE HERE
- char first_name[20];
- char last_name[20];
- DATE birth_date;
- long int nid;
- char address[200];
- } PERSON;
- void print_options()
- {
- // DO NOT MAKE ANY CHANGE HERE
- printf("*******************************************\n");
- printf("1: Calculating multiplication using recursion\n");
- printf("2: Testing symmetricity for a matrix\n");
- printf("3: Finding frequency of letters in a line\n");
- printf("4: Storing a person's information in a structure\n");
- printf("q: quit\n");
- printf("*******************************************\n");
- printf("Enter a option: ");
- }
- int recursion_task()
- {
- int x,y;
- printf("\nEnter the first number: ");
- scanf("%d", &x);
- printf("Enter the second number: ");
- scanf("%d", &y);
- printf("Result is: %d", result(x,y));
- return 0;
- }
- int result (int n1,int n2)
- {
- if(n2==0)
- return 0;
- if(n2>0)
- return (n1+result(n1,n2-1));
- if(n2<0)
- return -result(n1,-n2);
- }
- void array_task()
- {
- int n, i, j, k;
- printf("Enter dimension of the matrix: ");
- scanf("%d", &n);
- int arr[n][n];
- printf("Enter the matrix:\n");
- for(i = 0; i < n; i++)
- for(j = 0; j < n; j++)
- scanf("%d", &arr[i][j]);
- int sym = 0;
- for(i = 0; i < n; i++)
- {
- for(j = 0; j < n; j++)
- {
- if(arr[i][j] == -arr[j][i])
- sym = -1;
- else if(arr[i][j] != arr[j][i])
- sym = 1;
- }
- }
- if(!sym)
- printf("Symmetric matrix\n");
- else if(sym == -1)
- printf("Skew-symmetric matrix\n");
- else
- printf("Asymmetric matrix\n");
- }
- void string_task()
- {
- char str[1000];
- printf("Enter the line: ");
- gets(str);
- int len = strlen(str);
- int occ[30];
- for(int i = 0; i < 30; i++)
- occ[i] = 0;
- for(int i = 0; i < len; i++)
- {
- int id = str[i] - 'A';
- occ[id]++;
- }
- for(int i = 0; i < 26; i++)
- {
- printf("%c\t%d\t\t", 'A'+i, occ[i]);
- }
- }
- void structure_task()
- {
- PERSON temp;
- printf("Provide citizen Information....\n\n");
- printf("First Name: ");
- scanf("%s", temp.first_name);
- printf("Last Name: ");
- scanf("%s", temp.last_name);
- printf("\nDate of Birth...\n\n");
- printf("Date: ");
- scanf("%d", &temp.birth_date.day);
- printf("Month: ");
- scanf("%d", &temp.birth_date.month);
- printf("Year: ");
- scanf("%d", &temp.birth_date.year);
- printf("\nNID: ");
- scanf("%lld", &temp.nid);
- printf("\nAddress: ");
- gets(temp.address);
- gets(temp.address);
- printf("**************************************\n");
- printf("%s %s\n", temp.first_name, temp.last_name);
- printf("Date of Birth: %d-%d-%d\n", temp.birth_date.day, temp.birth_date.month, temp.birth_date.year);
- int cnt1 = 0, cnt2 = 0, temp1, temp2;
- temp1 = temp.birth_date.day, temp2 = temp.birth_date.month;
- while(temp1)
- {
- cnt1++;
- temp1 /= 10;
- }
- while(temp2)
- {
- cnt2++;
- temp2 /= 10;
- }
- printf("NID: %d ", temp.birth_date.year);
- if(cnt2 == 1)
- printf("0");
- printf("%d", temp.birth_date.month);
- if(cnt1 == 1)
- printf("0");
- long long int id = temp.nid;
- printf("%d %I64d\n", temp.birth_date.day, id);
- printf("Address: %s\n", temp.address);
- printf("**************************************\n");
- }
- int main()
- {
- // DO NOT MAKE ANY CHANGE HERE
- char op,c;
- do
- {
- print_options();
- fflush(stdin); //If we don't clear the standard input, we will keep getting '\n' after the first operation in op which will cause the wrong operation
- scanf("%c%c", &op,&c);
- switch(op)
- {
- case '1':
- recursion_task();
- break;
- case '2':
- array_task();
- break;
- case '3':
- string_task();
- break;
- case '4':
- structure_task();
- break;
- case 'q': //for not showing default in case of quit
- break;
- case 'Q': //for not showing default in case of quit
- break;
- default:
- printf("\nEnter a valid option\n");
- break;
- }
- printf("\n\n");
- }
- while(op!='q' && op!='Q');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement