Advertisement
murad45

Assignment Murad 202-35-651

Apr 8th, 2021
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.60 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4.  
  5.     int select;
  6.  
  7.     printf("\n 1. C program to delete element from an array");
  8.     printf("\n 2. C program to find reverse of array");
  9.     printf("\n 3. C Program to find the sum of all elements of each column of a matrix");
  10.  
  11.     printf("\n\n Select any program you want to Run :");
  12.     scanf("%d", &select);
  13.     if(select == 1){
  14.             int array[50], addnumber, removenumber, stored,option, arr,found=0;
  15.  
  16.             printf("\n\n 1) press 1 to Number of array");
  17.             printf("\n 2) press 2 to addnumber");
  18.             printf("\n 3) press 3 to removenumber");
  19.             printf("\n 4) press 4 to show the result");
  20.  
  21.             printf("\n\n enter any option: ");
  22.             scanf("%d", &option);
  23.  
  24.             if(option == 1){
  25.                 printf("\n\nEnter number of elements in array:");
  26.                 scanf("%d", &arr);
  27.                 printf("\n\n you have %d elements slot", arr);
  28.  
  29.                 printf("\n\n enter any option: ");
  30.                 scanf("%d", &option);
  31.                 if(option == 2){
  32.                     printf("\nEnter the elements you want to show: \n");
  33.                     for(addnumber = 0; addnumber < arr; addnumber++)
  34.                     scanf("%d", &array[addnumber]);
  35.  
  36.                     printf("you added these numbers :  ");
  37.                     for(addnumber = 0; addnumber < arr; addnumber++)
  38.                     printf("%d ", array[addnumber]);
  39.  
  40.                     printf("\n\n enter any option: ");
  41.                     scanf("%d", &option);
  42.  
  43.  
  44.                     if(option == 3){
  45.                     printf("\n\nEnter the element to be deleted: ");
  46.                     scanf("%d", &removenumber);
  47.                         for(addnumber=0; addnumber < arr; addnumber++){
  48.                             if(array[addnumber] == removenumber)
  49.                             {
  50.                                 found = 1;
  51.                                 stored = addnumber;
  52.                                 continue;
  53.  
  54.                             }
  55.                         }
  56.                         if(found == 1)
  57.                         {
  58.                             for(addnumber = stored; addnumber < arr-1; addnumber++)
  59.                                 array[addnumber] = array[addnumber+1];
  60.  
  61.                         }
  62.                         else{
  63.                             printf("\n\nElement %d is not found in the array\n\n", removenumber);
  64.  
  65.                         }
  66.  
  67.                         printf("\n\n enter any option: ");
  68.                         scanf("%d", &option);
  69.                             if(option == 4){
  70.                                 printf("\n\nResultant array is: ");
  71.                                 for(addnumber = 0; addnumber < arr-1; addnumber++)
  72.                                     printf("%d  ",array[addnumber]);
  73.  
  74.                             }
  75.  
  76.                     }
  77.  
  78.                 }
  79.                 else if (option == 1){
  80.                     printf("\nyou Already decided the size\n");
  81.  
  82.                 }
  83.                 else{
  84.                     printf("\nplease enter the numbers first\n");
  85.                 }
  86.  
  87.              }
  88.              else if(option == 2 || option == 3 || option == 4){
  89.                 printf("\n Please add some number first");
  90.              }
  91.             }
  92.  
  93.     else if(select == 2) {
  94.  
  95.         int arr2[50], arrsize, addNumbers, option2;
  96.  
  97.         printf("\n\n 1) Add size of array");
  98.         printf("\n 2) Add arrays numbers");
  99.         printf("\n 3) Reverse numbers");
  100.  
  101.         printf("\n Enter the option : ");
  102.         scanf("%d", &option2);
  103.  
  104.         if(option2 == 1){
  105.             printf("Enter size of the array: ");
  106.             scanf("%d", &arrsize);
  107.  
  108.             printf("\n Enter the option : ");
  109.             scanf("%d", &option2);
  110.  
  111.             if (option2 == 2){
  112.  
  113.                 printf("\n Enter the numbers to add in arrays : \n");
  114.                 for(addNumbers=0; addNumbers < arrsize; addNumbers++){
  115.                     scanf("%d", &arr2[addNumbers]);
  116.  
  117.                 }
  118.  
  119.                 printf("\n Enter the option : ");
  120.                 scanf("%d", &option2);
  121.                 if(option2 == 3){
  122.                         printf("\nReverse order of your added array : \n");
  123.                         for(addNumbers=arrsize-1; addNumbers >= 0; addNumbers--){
  124.                         printf("%d\n", arr2[addNumbers]);
  125.                     }
  126.                 }
  127.  
  128.  
  129.             }
  130.             else if (option2 == 1){
  131.                 printf("you already decide the size");
  132.             }
  133.             else{
  134.                 printf("add numbers first");
  135.             }
  136.         }
  137.         else{
  138.             printf("\n Please decide the size of array first \n");
  139.         }
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.     }
  149.  
  150.     else{
  151.         int maxrow= 10;
  152.         int maxcol = 10;
  153.         int matrix[maxrow][maxcol];
  154.         int row, col, sum, product, i,j;
  155.  
  156.         printf("\n\nenter number of Rows: ");
  157.         scanf("%d", &row);
  158.  
  159.         printf("\nenter number of columns: ");
  160.         scanf("%d",&col);
  161.  
  162.         printf("Enter the matrix numbers : \n");
  163.         for(i = 0; i<row; i++){
  164.             for(j=0; j< col; j++){
  165.                 printf("\nEnter Numbers [%d,%d]",i+1, j+1);
  166.                 scanf("%d", &matrix[i][j]);
  167.             }
  168.  
  169.         }
  170.         printf("\n");
  171.         for (i=0; i<row;i++){
  172.             sum=0;
  173.             for(j=0;j<col;j++){
  174.                 printf("%d\t", matrix[i][j]);
  175.                 sum += matrix[i][j];
  176.             }
  177.             printf("\t Sum : %d", sum);
  178.             printf("\n");
  179.         }
  180.  
  181.  
  182.  
  183.  
  184.     }
  185.  
  186.         return 0;
  187.  
  188. }
  189.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement