Monday 1 August 2016

Barracuda networks (A Bangalore's Startup) written Round Programming Questions


1) C program to copy one file to another.


#include<bits/stdc++.h>

using namespace std;

int main()
{
    char ch,src[20],tgt[20];
    FILE *s,*t;

    gets(src);
    s=fopen(src,"r");
    if(s==NULL)
    {
        printf("press any key to exit\n");
        exit(EXIT_FAILURE);
    }


    gets(tgt);
    t=fopen(tgt,"w");
    if(t==NULL)
    {
        printf("press any key to exit\n");
        exit(EXIT_FAILURE);
    }


    while(( ch=fgetc(s))!=EOF)
        fputc(ch,t);

    return 0;

}


-----------------------------------------------------------------------------------------------------------------------

2 ) use function pointer to add , sub and multiply

#include<bits/stdc++.h>

using namespace std;

int add(int a,int b)
{
return a+b;
}


int sub(int a,int b)
{
return a-b;
}


int mul(int a,int b)
{
return a*b;
}


int main()
{
    typedef int (*a)(int,int); /// a is now declared as type

    a fp[3]={add, sub ,mul};

 int n;
 cin>>n;
 int c,b;
 cin>>c>>b;

if(n==0)
    cout<<fp[0](c,b)<<endl;
else if(n==1)
    cout<<fp[1](c,b)<<endl;
else
    cout<<fp[2](c,b)<<endl;

return 0;
}

No comments:

Post a Comment

Uploading and Running Lambda function in AWS

Main.go package main import ( "fmt" "encoding/json" "log" "github.com/aws/aws-lambda-g...