Tcs question C program to find LCM in command line

#include <stdio.h>


 int main(int argc, char *argv[])
 {

 int lcm,i,num1,num2,max_value=0;
  num1=atoi(argv[1]);
  num2=atoi(argv[2]);
   
   max_value=(num1>num2)?num1:num2;
   
  while(1){//Always true till we get the lcm
      
       if(max_value%num1==0&&max_value%num2==0){
           
       printf("LCM is :%d",max_value);
       break;
       }
       ++max_value;
  }
  
  

return 0;
}

Tcs question find out gcd of two number in c using command line

#include <stdio.h>


 int main(int argc, char *argv[])
 {

 int gcd,i,num1,num2=0;
  num1=atoi(argv[1]);
  num2=atoi(argv[2]);
   
  
  for(i=1;i<=num1 && i<=num2;i++){
      
      if(num1%i==0 && num2%i==0){
      gcd=i;
          
      }
  }
  printf("GCD is :%d",gcd);

return 0;
}


Tcs question print string in c using command line

#include <stdio.h>

int main(int argc,char *argv[])
{
     
    if(argc==1){
        printf("Error:Please enter atleast one argument");
        return 0;
    }
    
//Note:- argv[0] is by default 0 our input string start storing from argv[1]. So it's better to start for loop from 1

      int i,v=0,size=argc-1;
      
      char *str;//intialize pointer
      
      //allocate memory to which pointer points
      
      str=(char*)malloc(v);//intially zero
      
      //now re allocate memory as per size of input sting arguments
      for(i=1;i<=size;i++){
          
     int length=v+strlen(argv[i]);
      str=(char*)realloc(str,length);
      
      //now concatenate the string argument
      strcat(str,argv[i]);
      //give a namespace
      strcat(str," ");
      }
      
      //now print string use %s not %concatenate
      printf("%s\n",str);
      
      return 0;
      
     
     
}

Link list of three nodes with insert display and delete

 #include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node{
    int label;
    char oper;
    int address;
     struct node *next;
};
//shorting the name
typedef struct node node;

node *head;

//Display function
void display(){
    if(head==NULL)
    {
        printf("There is no node \n");
    }
    //Create temporary node t
    node *t=head;
  
    while(t){
        printf("%d\t",t->label);
    
        printf("%c\t",t->oper);
        
        printf("%d\t",t->address);
        
        t=t->next;
    }
  
}


//Insert function
void insert(){
  
    int a,c;
    char b;
  
    //create new node
    node *nnode=(node*) malloc(sizeof(node));
    printf("Enter Label,Operator,Address\n\n");
  
    scanf("%d",&a);//Label
    getchar();
    scanf("%c",&b);//oper
    getchar();
    scanf("%d",&c);//address
    getchar();
    printf("\n");
    nnode->label=a;
    nnode->oper=b;
    nnode->address=c;
  
    if(head==NULL){
        nnode->next=NULL;
        head=nnode;
    }
    else{
        //insert at the end
        node *t=head;
        while(t->next){
            //traverse until t->next=NULL
            t=t->next;
        }
      
        t->next=nnode;//New node will be inserted at the end
        nnode->next=NULL;
      
      
    }
}

void remove(int l){
  
    node *t=head;//store head so it do not change
    node *p;
    p=t;//Take head address to temp pointer to remove it
  
    if(head==NULL){
        printf("There is nothing to delete\n\n");
        
        return;
    }
    if (t!=NULL && t->label==l){
        //This is single or first node to delete t->NULL
    free(t);
    head=NULL;
         return;
      
    }
  
    while(t->next!=NULL && t->label!=l){
        p=t;
        t=t->next;
    }
  
    if(t==NULL){
        printf("Item is not available\n\n");
         return;
    }
  
/*    if(t->label==l)
    {
        head=t->next;
        free(t);
        return;
    }*/
    p->next=t->next;
    free(t);
  
    return;
}

int main(){
  
    int l,ch;
  
    do{
        printf("*Enter Your choice*\n1.Insert Node\t2.Display List\t3.Delete Node\t4.Exit\n");
      
        printf("Choice:\t");scanf("%d",&ch);printf("\n");
      
        switch(ch){
            case 1:
                insert();
                break;
              
                case 2:
                    printf("Display:-");
                    display();
                    printf("\n\n");
                    break;
                  
                    case 3:
                        printf("Enter label to remove:-\t");
                        scanf("%d",&l);
                        remove(l);
                        break;
                      
                        case 4:
                         exit(0);
                      
                        
            default:
                printf("Wrong choice try again\n");
        }
    }while(ch<=3);
  
}