0% found this document useful (0 votes)
26 views

Assignment 9

The document contains 10 coding questions that involve taking input of 7 numbers, performing calculations on them using loops and functions, and outputting the final sum. Each question has a different mathematical operation or function applied to the input numbers during the nested for loops to calculate the sum. The output below each question confirms the input numbers and displays the final sum.

Uploaded by

AYAN PANJA
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Assignment 9

The document contains 10 coding questions that involve taking input of 7 numbers, performing calculations on them using loops and functions, and outputting the final sum. Each question has a different mathematical operation or function applied to the input numbers during the nested for loops to calculate the sum. The output below each question confirms the input numbers and displays the final sum.

Uploaded by

AYAN PANJA
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

QUESTION 1

#include <stdio.h>
#include<math.h>
int main()
{
int x[7];
int sum=0;
for(int i=0;i<7;i++){
printf("enter no: ");
scanf("%d",&x[i]);
}
for(int j=1;j<6;j++){
sum=sum+(x[j-1]+x[j])*x[j+1];
}
printf("ANSWER IS %d\n",sum);

return 0;
}
OUTPUT
enter no: 4
enter no: 5
enter no: 2
enter no: 5
enter no: 6
enter no: 4
enter no: 7
ANSWER IS 209
QUESTION 2
#include <stdio.h>
int main()
{
int x[7];
int sum=0;
for(int i=0;i<7;i++){
printf("enter no: ");
scanf("%d",&x[i]);
}
for(int j=1;j<6;j++){
sum=sum+(x[j-1]+x[j+1])*x[j];
}
printf("ANSWER IS %d\n",sum);

return 0;
}
OUTPUT
enter no: 4
enter no: 5
enter no: 2
enter no: 5
enter no: 6
enter no: 4
enter no: 7
ANSWER IS 196
QUESTION 3
#include <stdio.h>
int main()
{
int x[7];
int sum=0;
for(int i=0;i<7;i++){
printf("enter no: ");
scanf("%d",&x[i]);
}
for(int j=1;j<6;j++){
sum=sum+(x[j-1]-x[j])*(x[j]+x[j+1]);
}
printf("ANSWER IS %d\n",sum);

return 0;
}
OUTPUT
enter no: 4
enter no: 5
enter no: 2
enter no: 5
enter no: 6
enter no: 4
enter no: 7
ANSWER IS -7
QUESTION 4
#include <stdio.h>
int main()
{
int x[7];
int sum=0;
for(int i=0;i<7;i++){
printf("enter no: ");
scanf("%d",&x[i]);
}
for(int j=0;j<4;j++){
sum=sum+(x[j]-x[j+1])*(x[j+1]+x[j+3]);
}
printf("ANSWER IS %d\n",sum);

return 0;
}
OUTPUT
enter no: 4
enter no: 5
enter no: 2
enter no: 5
enter no: 6
enter no: 4
enter no: 7
ANSWER IS -26
QUESTION 5
#include <stdio.h>
int main()
{
int x[7];
int sum=0;
for(int i=0;i<7;i++){
printf("enter no: ");
scanf("%d",&x[i]);
}
for(int j=0;j<7;j++){
sum=sum+(x[j]*x[6-j]);
}
printf("ANSWER IS %d\n",sum);

return 0;
}
OUTPUT

enter no: 4
enter no: 5
enter no: 2
enter no: 5
enter no: 6
enter no: 4
enter no: 7
ANSWER IS 145
QUESTION 6
#include <stdio.h>
int main()
{
int x[7];
int sum=0;
for(int i=0;i<7;i++){
printf("enter no: ");
scanf("%d",&x[i]);
}
for(int j=0;j<6;j++){
sum=sum+(x[j]+x[j+1])*(j+1);
printf(" %d\n",sum);

}
printf("ANSWER IS %d\n",sum);

return 0;
}
OUTPUT

enter no: 4
enter no: 5
enter no: 2
enter no: 5
enter no: 6
enter no: 4
enter no: 7
ANSWER IS 204
QUESTION 7
#include <stdio.h>
#include<math.h>
int main()
{
int x[7];
int sum=0;
for(int i=0;i<7;i++){
printf("enter no: ");
scanf("%d",&x[i]);
}
for(int j=0;j<7;j++){
sum=sum+pow(x[j],j+1);
}
printf("ANSWER IS %d\n",sum);

return 0;
}
OUTPUT
enter no: 4
enter no: 5
enter no: 2
enter no: 4
enter no: 6
enter no: 4
enter no: 7
ANSWER IS 836077
QUESTION 8
#include <stdio.h>
#include<math.h>
int main()
{
int x[7];
int sum=0;
for(int i=0;i<7;i++){
printf("enter no: ");
scanf("%d",&x[i]);}
int f(int a,int b) {
int c=1;
for(int i=1;i<=b;i++){
c=c*a;}
return c; }
for(int j=0;j<7;j++){
sum=sum+f(x[j],j+1);}
printf("ANSWER IS %d\n",sum);
return 0;
}
OUTPUT
enter no: 4
enter no: 5
enter no: 2
enter no: 5
enter no: 6
enter no: 4
enter no: 7
ANSWER IS 836077
QUESTION 9
#include <stdio.h>
#include<math.h>
int main()
{
int x[7];
int sum=0;
for(int i=0;i<7;i++){
printf("enter no: ");
scanf("%d",&x[i]);
}
for(int j=0;j<6;j++){
sum=sum+pow(x[j]+x[j+1],j+1);
}
printf("ANSWER IS %d\n",sum);

return 0;
}
OUTPUT
enter no: 4
enter no: 5
enter no: 2
enter no: 5
enter no: 6
enter no: 4
enter no: 7
ANSWER IS 1886603
QUESTION 10
#include <stdio.h>
#include<math.h>
int main()
{
int x[7];
int sum=0;
for(int i=0;i<7;i++){
printf("enter no: ");
scanf("%d",&x[i]);}
int f(int a,int b) {
int c=1;
for(int i=1;i<=b;i++){
c=c*a;}
return c; }
for(int j=0;j<6;j++){
sum=sum+f((x[j]+x[j+1]),j+1); }
printf("ANSWER IS %d\n",sum);
return 0;
}
OUTPUT
enter no: 4
enter no: 5
enter no: 2
enter no: 5
enter no: 6
enter no: 4
enter no: 7
ANSWER IS 1886603

You might also like