I’ve put together the number6 one but if a different way from how my teacher adv
ID: 3873135 • Letter: I
Question
I’ve put together the number6 one but if a different way from how my teacher advised me. As for number 7 I’m not sure what to do, I keep getting a crashed code. Some help would be much appreciated. Q6. (10 points) Average Write a code in C to calculate the average (AVG) of the integers entered by a user. ask the user to enter the values. to show the end of data entry use -1. Print the average like the following example: (suppose the user has entered 2, 3, 4) The average value is 3.00, Use the following formula for calculating average of n integers x1, x2.,..Xn AVG (x1+ x2+...Xn)/n The default is the user enters just positive integer numbers. (-1 is sentinel value.) Q7. (15 points) Perfect square In mathematics, a square number, sometimes also called a perfect square, is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 9 is a square number, since it can be written as 3x3. (Text from Wikipedia) Write a program to check if the input number (less than 1000) is the summation of two perfect square or not. For example 25 is 16+9 that both numbers 16 and 9 are perfect square. The output should be such as the following examples: If input is 3 the message should be: 3isnota summation oftwoperfect square. 25 is the summation of two perfect square, because If input is 25: the message should be: 25-SQ (3) +SQ (4Explanation / Answer
6)
#include <stdio.h>
int main() {
int i,total;
int count=0;
int num=0;
while(num!=-1){
printf("Enter next number (-1 to end) ");
scanf("%d",&num);
if(num==-1)break;
total=total+num;
count=count+1;
}
printf("Average = %f ", total/(float)count);
return 0;
}
7)
#include <stdio.h>
int isperfectsquare(int n);
int main(){
int i,n,a;
printf("Enter a number: ");
scanf("%d", &n);
for(a = 1; a <= n; a++){
if(isperfectsquare(a) && isperfectsquare(n-a)){
printf("%d is the summation of two perfect squares,namely %d and %d ",n,a,n-a);
return 0;
}
}
printf("%d is not a summation of two perfect square ",n);
return 0;
}
int isperfectsquare(int n)
{
int a;
for(a = 0; a <= n; a++)
{
if (n == a * a)
{
return 1;
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.