Write a program containing a function that takes 2 integer parameters x and y and returns the value of x2 + y2. The main program should then allow the input of two integer values a and b and display the value of a2+b2.
Can someone help me?am having this error:
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token

Whats wrong in this program?

I write n compile my program using linux terminal.

#include <stdio.h>

int submain(int a,int b)
{
	return (a*a)+(b*b);
}

int main
{
	int x,y,ans;

	printf("Enter value of x: ");
	scanf("%d", &x);
	printf("Enter value of y: ");
	scanf("%d", &y);
	ans=submain(x,y);
	printf("(x*x)+(y*y) %d",ans);
	return 0;
	
}
Member Avatar for Mouche

You are not using the correct format for the main function. You are missing the () arguments section.

It should look like this or something similar:

int main(int argc, char *argv[])
{
  // Code here
  return 0;
}

Thanks it works :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.