TAB

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Friday 29 January 2016

ASSESSMENT 1 MCQ

1.DIFFICULTY=HARD

Q.Scope of an external variable in C

a.Whole program where it is defined.
b.From the point of declaration to the point of end of file in which it is defined
c.Any source file that is linked.
d.From the point of declaration to the end of the file being compiled.

It must be (d). I am not entirely sure though.I will update once i get a confirmed explaination. Your answers with justification are always welcomed in the comments.

--------------------------------------------------------------------------------------------------------------------------
2.DIFFICULTY=EASY

Q.In the following loop construct which statement is executed only once.
for(exp1,exp2,exp3)

Sol. It has to be exp1 as it is the variable initialization which occurs only in the beginning .exp2 is the condition statement which is checked on every iteration and exp3 is the incrementation which is also executed everytime.

Ans. Exp1
--------------------------------------------------------------------------------------------------------------------------
3.DIFFICULTY=MEDIUM

Q.a=100 ;b=200;c=300
what will be the output of:
if(!a>=500)
b=300;
c=400;
printf("%d %d %d,a,b,c);

Sol. Firstly since the statement "c=400;" is outside the if block it will be executed irrespective of the if condition. Then the '!a' can be replaced with the ternary expression (a==0)?1:0. and then conpare the result with 500. Here since a is not 0 the value of !a is 0 which is not greater than or equal to 500 thus b=300 is never executed.

Ans.100 200 400

--------------------------------------------------------------------------------------------------------------------------
4.DIFFICULTY=EASY

Q. '&&' Operator in C is:

Ans : Logical AND
-------------------------------------------------------------------------------------------------------------------------
5.DIFFICULTY=HARD

Q. Character literals in C are denoted as :

Sol. Strings are represented in double-quotes ("example") and character in single quotes('c').

Ans. 'A'
--------------------------------------------------------------------------------------------------------------------------
6.DIFFICULTY=MEDIUM

Q.If a is an integer ,on executing a<<2 a becomes:

Sol. << is the left shift operator. It shifts the bits of the number in binary notation to the left side.
Example (101)<<1 becomes (1010)
and (1001)<<2 becomes (100100)
Thus here when a deimal number is converted to binary and left-shifted by 2 bits it gets "multiplied by 4"
Example : (2) in decimal is (10) in binary.Thus (10)<<2 is (1000) which corressponds to 8 in decimal system.

Ans. Multiplied by 4.
-------------------------------------------------------------------------------------------------------------------------
7.DIFFICULTY=EASY

Q.How many times will "Hello" be printed?

int i;
for(i=0;i<10;i++);
printf("Hello");

Sol. Common mistake is to say it will be printed "10 times" but actually we  miss the ';' at the end of the for loop in a hurry. Thus the body of the for loop is empty and "Hello" will be printed "only once"
Ans. 1 time.
--------------------------------------------------------------------------------------------------------------------------
8.Undefined function calls in C are detected by:

Sol.Refer : THIS. Correct me if i am wrong it must be "The Linker".

And."The Linker".
-------------------------------------------------------------------------------------------------------------------------
9.
Which keyword is used to come out of the loop for only that iteration.

Sol. The "continue" keyword is used for the following purpose.

Ans."continue"
------------------------------------------------------------------------------------------------------------------------
10. A bit field is :

Sol.Bit field in C is used to specify the width(of bits or bytes) required to store the variable.REFER THIS.

Ans. One Bit or a set of adjacent bits of a word.

------------------------------------------------------------------------------------------------------------------------
Please let me know in the comment if you have additional questions i will make sure to add them here.
And please do not hesitate to ask if you want further explaination on a particular solution,ill do my best.
As of the first question ,i will update as soon as i get a confirmed answer.








Thursday 28 January 2016

PRACTICE PROBLEM 2 : (24-1 to 27-1) : Local Machines


It can be solved in a more efficient manner by using a struct to store several pairs of ip and corresponding name of the machine.However i have simply used a 2d array for ip and name.
I would encourage people to use struct.

 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#include<stdio.h>
#include<string.h>
void main()
{
int i,j,t;
scanf("%d",&t);
char name[t][100];
char ip[t][100];
for(i=0;i<t;i++)
{
scanf("%s",ip[i]);
scanf("%s",name[i]);
}/*
for(i=0;i<t;i++)
{
printf("%s\n",ip[i]);
printf("%s",name[i]);
}*/
for(i=0;i<t;i++)
{
        int found=0;
        int c=0;
        char search[10];
        int k=0;
        while(c<2)
        {
            char temp[100];
            strcpy(temp,ip[i]);
            if(temp[k]=='.')
            {c++;}
            search[k]=temp[k];
            k++;
        }
        for(j=i+1;j<t;j++)
        {
            char search2[k];
            strncpy(search2,ip[j],k);
            if(strcmp(search,search2)==0)
            {
                printf("Machines %s and %s are on the same local network\n",name[i],name[j]);
            }

        }
    }
    }

ASSESSMENT WEEK 1 (HERE COMES THE FIRST TEST)!

Firstly,All the very best to everyone.!
As for the pattern
There will be 10 MCQ questions,5 Debugging questions,2 coding challenges.
All of these will cover concepts of C programming only.
MCQ will be really tricky, carefully read the question before answering.
1 Debugging is usually found to be really tricky,save it for the last as they weigh only 2 marks.
Focus on the Coding challenges once you have finished the MCQ's.
As of the coding problems,one of them will be small and easy ,attempt to finish it off first and the go to the longer(usually harder) problem.

Go through previous practice problems,they should cover most of the concepts taught.
Additionally practice pointer ,tructure implementation and string manipulation.
For additional practice try :C-PROGRAMS
Do the 2,3,4,5 Chapters and 2D arrays sections

Wednesday 27 January 2016

PRACTICE PROBLEM 2 :(24-1 to 31-1) :'L' Pattern

======================================================================== #include<stdio.h>
void main()
{
int i,j;
int r,c;
scanf("%d %d",&r,&c);
char a[r][c];
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf(" %c",&a[i][j]);
int check=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
int x,y;
x=i;
y=j;
int up,right;
up=0;
right=0;
//ANALYSING
while(x>0)
{
//printf("checking up\n");
x--;
if(a[x][y]==a[i][j])
up++;
else
break;
}
x=i;
while(y<c)
{
//printf("checking right\n");
y++;
if(a[x][y]==a[i][j])
right++;
else
break;
}
//printf("%d %d",up,right);
if(up!=0 && up==right)
{
printf("Yes");
check=1;break;
}
}
if(check==1)
{break;}
}
if(check==0)
printf("No");
}

Tuesday 26 January 2016

PRACTICE PROBLEM 2(24-1 to 31-1):COMPLEX NUMBERS

I had to forcefully format the output in the required manner.
For example it had to be +i and not +1i ..
So not much logic in this problem except for the calculation.
========================================================================


#include<stdio.h>
void add(int,int,int,int);
void sub(int,int,int,int);
void mul(int,int,int,int);
int main()
{
  int a,b,c,d;
  scanf("%d\n%d\n%d\n%d",&a,&b,&c,&d);
  add(a,b,c,d);
  sub(a,b,c,d);
  mul(a,b,c,d);

  return 0;

}
void add(int a,int b,int c,int d)
{
  if(b+d==1)
  printf("%d+i\n",a+c);
  else if(b+d==-1)
  printf("%d-i\n",a+c);
  else if(b+d>=0)
  printf("%d+%di\n",a+c,b+d);
  else
  printf("%d%di\n",a+c,b+d);
}
void sub(int a,int b,int c,int d)
{
  if(b-d==1)
  printf("%d+i",a-c);
  else if(b-d==-1)
  printf("%d-i",a-c);
  else if(b-d>=0)
  printf("%d+%di\n",a-c,b-d);
  else
  printf("%d%di\n",a-c,b-d);
}
void mul(int a,int b,int c,int d)
{
  if(a*d+b*c==1)
  printf("%d+i",a*c-b*d);
  else if(a*d+b*c==-1)
  printf("%d-i",a*c-b*d);
  else if(a*d+b*c>=0)
  printf("%d+%di",a*c-b*d,a*d+b*c);
  else
  printf("%d%di",a*c-b*d,a*d+b*c);

}

PRACTICE PROBLEM 2 -(24-1 to 31-1) : SINGULAR TO PLURAL

#include<stdio.h>
#include<string.h>
int main()
{

char s[100];
char p[100];
scanf("%s",s);
int l=strlen(s);
char last=s[l-1];
char last_two[2];
last_two[0]=s[l-2];
last_two[1]=s[l-1];
int i;
for(i = 0; s[i]; i++){
    s[i] = tolower(s[i]);
    }
strcpy(p,s);
if(strcmp(last_two,"ch")==0 || strcmp(last_two,"sh")==0 || last=='s')
{
p[l]='e';
p[l+1]='s';
p[l+2]='\0';
    }
   
else if(last=='y')
{
p[l-1]='i';
p[l]='e';
p[l+1]='s';
p[l+2]='\0';
    }
    else
    {
    p[l]='s';
}
printf("%s %s",s,p);
return 0;
}

PRACTICE PROBLEMS 2 (24-1 to 31-1) : CIRCULAR PRIMES

Please do not blindly copy/paste.Try understanding it.
For a detailed explaination :VIDEO HERE
Please let me know if i should continue making such videos where in i explain the solution.
---------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<math.h>
int len(int);
int prime(int);
void main()
{
int N;
int i;
scanf("%d",&N);
int r=len(N);
int p=0;
for(i=1;i<=r;i++)
{
int num=N;
int j;
int le=len(N);
for(j=0;j<i;j++)
{
int rem=num%10;
num=(num/10)+(rem*pow(10,le-1));
}
int result=prime(num);
if(result==1)
p++;
}
if(p==r)
printf("Circular prime");
else
printf("Not circular prime");
}
int len(int a)
{
int l=0;
while(a>0)
{
l++;
a/=10;
}
return l;
}
int prime(int n)
{
int c=1;
int i;
for(i=2;i<n;i++)
{
if(n%i==0)
{
c=0;
break;
}
}
return c;
}

Friday 22 January 2016

PRACTICE PROBLEM 1 (20-1 to 27-1) : SPEED OF SOUND

#include<stdio.h>
#include<math.h>
void main()
{
int t;
scanf("%d",&t);
printf("%.2f",1086*sqrt(((5*t)+297.0)/247.0));
}

PRACTICE PROBLEM 1 (20-1 to 27-1) : EMISSION STANDARDS

#include<stdio.h>
void main()
{
int P,O;
float N;
scanf("%d",&P);
scanf("%f",&N);
scanf("%d",&O);
switch(P)
{
case 1:if(O<=50000)
{
if(N<=3.4)
{
printf("Emission do not exceed permitted level of 3.4 g/mile");
}
else
{
printf("Emission exceed permitted level of 3.4 g/mile");
}
}
else
{
if(N<=1)
{
printf("Emission do not exceed permitted level of 1 g/mile");
}
else
{
printf("Emission exceed permitted level of 1 g/mile");
}
}
break;
case 2:if(O<=50000)
{
if(N<=0.31)
{
printf("Emission do not exceed permitted level of 0.31 g/mile");
}
else
{
printf("Emission exceed permitted level of 0.31 g/mile");
}
}
else
{
if(N<=0.39)
{
printf("Emission do not exceed permitted level of 0.39 g/mile");
}
else
{
printf("Emission exceed permitted level of 0.39 g/mile");
}
}
break;
case 3:if(O<=50000)
{
if(N<=0.4)
{
printf("Emission do not exceed permitted level of 0.4 g/mile");
}
else
{
printf("Emission exceed permitted level of 0.4 g/mile");
}
}
else
{
if(N<=0.5)
{
printf("Emission do not exceed permitted level of 1.0 g/mile");
}
else
{
printf("Emission exceed permitted level of 1.0 g/mile");
}
}
break;
case 4:if(O<=50000)
{
if(N<=0.25)
{
printf("Emission do not exceed permitted level of 0.25 g/mile");
}
else
{
printf("Emission exceed permitted level of 0.25 g/mile");
}
}
else
{
if(N<=0.31)
{
printf("Emission do not exceed permitted level of 0.31 g/mile");
}
else
{
printf("Emission exceed permitted level of 0.31 g/mile");
}
}
break;
}
}

PRACTICE PROBLEM 1 (20-1 to 27-1) : BAKING A BREAD

#include<stdio.h>
void main()
{
float time=0.0;
char b,s,t;
scanf("%c\n%c\n%c",&b,&s,&t);
if(b=='w')
{
time=time+6782;
if(t=='a')
{
time=time+9000;
}

}
else
{
time=8582;
if(t=='a')
{
time=time+8400;
}
}
if(s=='d')
{
time=time+(time*0.5);
}
printf("%.0f",time);

}
/*P.S.:Use a blank space instead of "\n" in input console if skillrack shows an error indicating "use standard input console"*/

Practice Problem 1 (20-1 to 27-1) : SPEED CONVERSION

#include<stdio.h>
#include<math.h>
void main()
{
int m;
float s;
scanf("%d",&m);
scanf("%f",&s);
int time;
time=m*60;
time+=(int)(s+0.5);
float fps=5280.0/time;
fps=roundf(fps*100)/100;
float mps=1609.34/time;
mps=roundf(mps*100)/100;
printf("%.2f fps\n",fps);
printf("%.2f mps",mps);
}

Practice Problem 1 (20-1 to 27-1) : WAGE

#include <stdio.h>
#include<math.h>
void main()
{
    int I,R,N;
    scanf("%d %d %d",&I,&R,&N);
    float G=0.0;
    if(N>40)
    {
        G=40*R+(N-40)*R*1.5;
    }
    else
    {
        G=R*N;
    }
    G=G-G*0.03625;
    G=roundf(G*100)/100;
    printf("%.2f",G);
 
}

SO IT BEGINS...

Practice problems for the course CSE1002 :Problem Solving with Object Oriented Programming have been uploaded on skillrack.com
Though these five simple problems have to be solved in C, the focus will migrate towards C++ further on in the course.
Best Of Luck to all for the new Semester .
And better late than never "Have A Very Prosperous Year"
-Karthik.