0% found this document useful (0 votes)
24 views8 pages

End Term

The document contains code for 3 coding questions. The first question takes a number as input and calculates the mean of the digits plus the original number. The second question prints a triangle pattern based on the number of rows input. The third question checks if numbers in an array are prime, converts them to binary and calculates the sum as a final answer.

Uploaded by

tarun gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views8 pages

End Term

The document contains code for 3 coding questions. The first question takes a number as input and calculates the mean of the digits plus the original number. The second question prints a triangle pattern based on the number of rows input. The third question checks if numbers in an array are prime, converts them to binary and calculates the sum as a final answer.

Uploaded by

tarun gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

QUESTION NO 1

#include <stdio.h>
int main()
{
int mynum;
int digit[50];
int size;
int sum = 0;
int num;
int mean;
int count = 0;
printf("enter the size of number");
scanf("%d", &size);
if (size <= 50)
{

scanf("%d", &mynum);
for (int i = 0; i < size; i++)
{
digit[size - i - 1] = mynum % 10;
mynum = mynum / 10;
}

for (int i = 0; i < size; i++)


{
printf("%d ", digit[i]);
num = num * 10 + digit[i];
count++;
}
for (int i = 0; i < size; i++)
{
sum = sum + digit[i];
}

// printf("%d %d %d", num, sum, count);

mean = sum / count;


printf("\nAns is %d", mean + num);
}
else
{
printf("your size of num is greater than 50 please
enter less than 50 ;");
}

return 0;
}
output
enter the size of number 4

1234

1234

Ans is 1236

QUESTION 2
#include <stdio.h>
int main()
{
int N;

printf("enter no of ROWS");
scanf("%d", &N);
int b = N;
int a = N - 1;

for (int i = 1; i <= N * 2; i++)

{
if (i <= N)
for (int j = 1; j <= i; j++)
{
printf("* ");
}
else
{

for (int k = 1; k <= a; k++)


{
printf(" ");
}
a++;

for (int l = 1; l <= b; l++)


{
printf("* ");
}
b--;
}
printf("\n");
}

return 0;
}
output
enter no of lines4

* *

* * *

* * * *

* * * *

* * *

* *

QUESTION NO .3
#include <stdio.h>
#include <math.h>
int main()
{
int sum = 0;
int arr[5] = {14, 13, 45, 80, 101};
printf("Given array is ");
for (int i = 0; i < 5; i++)
{
printf("%d ", arr[i]);
if (arr[i] == 2)
{
arr[i] = 1;
}
}
for (int i = 0; i < 5; i++)
{
for (int j = 2; j <= arr[i] - 1; j++)
{
if (arr[i] % j == 0)
{
// not prime
arr[i] = 0;
break;
}
else if (j == arr[i] - 1)
{
arr[i] = 1;
}
}
}
printf("\nThe binary code is ");
for (int i = 0; i < 5; i++)
{
printf("%d ", arr[i]);
}
printf("\nthen the ans is ");
for (int i = 0; i < 5; i++)
{
sum = sum + (pow(2, i) * arr[4 - i]);
}
printf("%d", sum);
}

OUTPUT

Given array is 14 13 45 80 101


The binary code is 0 1 0 0 1

then the ans is 9

You might also like