writing a sum function for finding out the sum of vectors

 #include <stdio.h>

typedef struct vector {
    int x;
    int y;
}vec;

vec sumvector(vec v1,vec v2)
{
   
  vec result;  
result.x=v1.x+v2.x;
result.y=v1.y+v2.y;
return result;
}
int main(){
vec v1,v2;
v1.x=4;
v1.y=5;
printf("x dim is %d and y dim is %d\n",v1.x,v1.y);

v2.x=6;
v2.y=5;
printf("x dim is %d and y dim is %d\n",v2.x,v2.y);
vec result;
result=sumvector(v1,v2);
printf("The result is %d and %d:",result.x,result.y);
 return 0;
}

Comments

Popular posts from this blog

snake game Version-2 (using random number)

allocating dynamic memory using calloc

store a table in dynamic array and then change the size of array dynamically to store more numbers