C Programming – HackerRank Solution | TelePay application |

(HackerRank) Write a Modular C Programming code to solve TelePay application, TelePay is an application used by many people for online money transactions.

TelePay is an application used by many people for online money transactions. The application stores transaction details for money transferred to other people through TelePay. As the user is very much interested to know his transaction details, write a modular C program using Singly Linked List to store and display all the transactions performed. Also search and display all the transactions related to recharge. Available types of transactions are: dth, recharge, transfer and storepay.

Input Format

First Line indicates number of transactions.

Second Line onwards indicates details of each transaction.

Constraints

Number of transactions should be positive.

Output Format

Display all the transaction details.

Display transactions related to recharge.

Sample Input 0

5
dth 549 465770
storepay 1255 56774
recharge 395 989987
transfer 5000 77445
recharge 100 22312

Sample Output 0

All transactions details:
dth 549.00 465770
storepay 1255.00 56774
recharge 395.00 989987
transfer 5000.00 77445
recharge 100.00 22312

recharge 395.00 989987
recharge 100.00 22312

Sample Input 1

3
dth 549 465770
storepay 1255 56774
transfer 5000 77445

Sample Output 1

All transactions details:
dth 549.00 465770
storepay 1255.00 56774
transfer 5000.00 77445

No transactions found related to recharge.

Refer : C Programming HackerRank all solutions for Loops | Arrays | strings | Data Structures | Linked lists | Stacks | Queues | Binary Trees

 

CODE:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

struct node
{
    char tr[30];
    float rech;
    int str;
    struct node *link;
};
typedef struct node *NODE;
NODE newnode,cur;
NODE createnode();
NODE insert_e(NODE tail);
void display(NODE tail);
NODE recha(NODE tail);
NODE tail=NULL;
int main() 
{
    int i,n;
    scanf("%d",&n);
    if(n>0)
    {
        for(i=0;i<n;i++) { tail=insert_e(tail); } display(tail); tail=recha(tail); } else { exit(0); } return 0; } void display(NODE tail) { cur=tail->link;
    printf("All transactions details:\n");
    while(cur!=tail)
    {
        printf("%s %0.2f %d",cur->tr,cur->rech,cur->str);
        printf("\n");
        cur=cur->link;
    }
    printf("%s %0.2f %d",cur->tr,cur->rech,cur->str);
    printf("\n");
}
NODE createnode()
{
    newnode=(NODE)malloc(sizeof(struct node));
    if(newnode==NULL)
    {
        exit(0);
    }
    scanf("%s %f %d",newnode->tr,&newnode->rech,&newnode->str);
    newnode->link=newnode;
    return newnode;
}
NODE insert_e(NODE tail)
{
    newnode=createnode();
    if(tail==NULL)
    {
        tail=newnode;
    }
    else
    {
        newnode->link=tail->link;
        tail->link=newnode;
        tail=newnode;
    }
    return tail;
}
NODE recha(NODE tail)
{
    int k,count=0;
    scanf("%d",&k);
    cur=tail->link;
    printf("\n");
    while(cur!=tail)
    {
        if(strcmp("recharge",cur->tr)==0)
        {
            count++;
            printf("%s %0.2f %d\n",cur->tr,cur->rech,cur->str);
        }
        cur=cur->link;
    }
    if(strcmp("recharge",tail->tr)==0)
        {
            count++;
            printf("%s %0.2f %d",tail->tr,tail->rech,tail->str);
        }
    if(count==0)
        printf("No transactions found related to recharge.");
    
    return tail;
}

OUTPUT

Congratulations, you passed the sample test case.

Click the Submit Code button to run your code against all the test cases.

Input (stdin)

5
dth 549 465770
storepay 1255 56774
recharge 395 989987
transfer 5000 77445
recharge 100 22312
Your Output (stdout)

All transactions details:
dth 549.00 465770
storepay 1255.00 56774
recharge 395.00 989987
transfer 5000.00 77445
recharge 100.00 22312

recharge 395.00 989987
recharge 100.00 22312
Expected Output

All transactions details:
dth 549.00 465770
storepay 1255.00 56774
recharge 395.00 989987
transfer 5000.00 77445
recharge 100.00 22312

recharge 395.00 989987
recharge 100.00 22312

 

Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, Stacks, Queues, Binary Trees, MISC, Solved model question papers & Hacker Rank all solutions on the below page:

Top 100+ C Programming codes – KLE Technological University

Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

Welcome to FactsPrime

Sorry, We have detected that you have activated Ad-Blocker. Please Consider supporting us by disabling your Ad Blocker, It helps us in maintaining this website. To View the content, Please disable adblocker and refresh the page.

Thank You !!!