-1
main ()
{
int a,b,toplam;
float ort;

printif("iki sayi girin :");
scanf("%d,%d",%a,%b);
toplam=a+b;
ort=toplam/2;
printif("Ortalama= %f olarak hesaplandı.",ort);
}

error: expected expression before '%' token scanf("%d,%d",%a,%b); What was my mistake?

Yunnosch
  • 26,130
  • 9
  • 42
  • 54

3 Answers3

2

Replace scanf("%d,%d",%a,%b); with scanf("%d,%d",&a,&b);

Check this answer for more information.

Saurav Rai
  • 2,171
  • 1
  • 15
  • 29
2

You need to replace the '%' before a and b with '&'.
Also you need to use printf not printif.

int a,b,toplam;
    float ort;
    
    printf("iki sayi girin :");
    scanf("%d,%d",&a,&b);
    toplam=a+b;
    ort=toplam/2;
    printf("Ortalama= %f olarak hesaplandı.",ort);


    return 0;
mscandan
  • 37
  • 1
  • 4
0

Read Modern C and see this C reference

Your scanf statement should be (using the & prefix "address-of" operator):

 scanf("%d,%d",&a,&b);

and your code is incomplete, since scanf can fail. You should read its documentation.

Consider coding a test against such failure using:

if (scanf("%d,%d", &a, &b) < 2) {
   perror("scanf failure");
   exit(EXIT_FAILURE);
}

Read also the documentation of your C compiler, e.g. GCC, and of your debugger, e.g. GDB. You could compile your code with gcc -Wall -Wextra -g to get all warnings and debug information, and later use gdb to debug your executable and understand its runtime behavior.

Your code is missing a #include <stdio.h> before your main.

The printif is wrong. You want to use printf (and read its documentation).

Consider studying for inspiration the source code of some existing free software, such as GNU make or GNU bash.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547