Please find a Post-It™ Note and write “check for semi-colons at the end of for loops” and stick it to your monitor - this is ( least) thethird time you’ve made this mistake
Edit:
gcc even warns you about it:
Compiling negia-blah.cpp
Executing command:
g++ -std=c++17 negia-blah.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
negia-blah.cpp: In function ‘int main()’:
negia-blah.cpp:15:5: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
for(i=0;i<=9;i++);
^~~
negia-blah.cpp:17:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
{
^
negia-blah.cpp:29:15: warning: conversion to ‘int’ from ‘__gnu_cxx::__promote_2<int, int, double, double>::__type {aka double}’ may alter its value [-Wfloat-conversion]
r1=pow((x[i+1]-x[i]),2);
~~~^~~~~~~~~~~~~~~~~
negia-blah.cpp:31:15: warning: conversion to ‘int’ from ‘__gnu_cxx::__promote_2<int, int, double, double>::__type {aka double}’ may alter its value [-Wfloat-conversion]
r2=pow((y[i+1]-y[i]),2);
~~~^~~~~~~~~~~~~~~~~
negia-blah.cpp:33:18: warning: conversion to ‘float’ from ‘__gnu_cxx::__enable_if<true, double>::__type {aka double}’ may alter its value [-Wfloat-conversion]
z[i]=sqrt(r1+r2);
~~~~^~~~~~~
negia-blah.cpp:47:34: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Wformat=]
printf("the distance is %d",d);
^
negia-blah.cpp:19:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&x[i]);
~~~~~^~~~~~~~~~~~
negia-blah.cpp:21:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&y[i]);
~~~~~^~~~~~~~~~~~
Successful
int x[4], y[4], i, r1, r2;
int z[4], d = 0;
printf("enter the x and y corrdinate \n");
for (i = 0; i <= 3; i++)
{
scanf("%d", &x[i]);
scanf("%d", &y[i]);
}
for (i = 0; i <= 2; i++)
{
r1 = pow((x[i + 1] - x[i]), 2);
printf("the r1 is % d\n", r1);
r2 = pow((y[i + 1] - y[i]), 2);
printf("the r2 is % d\n", r2);
int p = r1 + r2;
z[i] = sqrt(p);
}
for (i = 0; i <= 2; i++)
{
d = d + z[i];
}
printf("the distance is % d", d);
return 0;