0% found this document useful (0 votes)
3 views9 pages

C B Answer Paper

The document contains multiple C programming questions and their corresponding solutions. Each question demonstrates different programming concepts such as array manipulation, loops, searching, prime number calculation, and structure usage. The solutions include code snippets that perform tasks like calculating sums, averages, identifying duplicates, and handling user input for phone numbers.

Uploaded by

mrl2227000
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)
3 views9 pages

C B Answer Paper

The document contains multiple C programming questions and their corresponding solutions. Each question demonstrates different programming concepts such as array manipulation, loops, searching, prime number calculation, and structure usage. The solutions include code snippets that perform tasks like calculating sums, averages, identifying duplicates, and handling user input for phone numbers.

Uploaded by

mrl2227000
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/ 9

Question 1

#include <stdio.h>

#include <stdlib.h>

int main() {

int sum=0;

int i=0;

int found = 0;

int searchNo=50;

int data[10] = {70,35,100,40,80,90,50,70,45,28};

int index;

int average;

printf("(a)Display array data.\n");

for( i=0;i<10;i++) { //a

printf("%5d",data[i]);

for( i=0;i<10;i++) { //b

sum+=data[i];

printf("(b)Sum of th element is %d\n",sum);


average = sum/10;

printf("/n(c)Average is %d",average);

for(i=0;i<10;i++) { //linear search

if(data[i]==searchNo) {

index=i;

found=1;

if(found==1) {

printf("/n(c)This number is position %d",index);

Question 2
#include <stdio.h>
int main() {

int i;

// (i) 1 2 3 4 5 7 9 11 13 15

printf("(i)\t");

for (i = 1; i <= 15; i += 2) {

if (i != 6) {

printf("%d\t", i);

printf("\n");

// (ii) 2 4 6 8 10 18 21 24 27 30

printf("(ii)\t");

for (i = 2; i <= 10; i += 2) {

printf("%d\t", i);

for (i = 18; i <= 30; i += 3) {

printf("%d\t", i);

printf("\n");

// (iii) 1 2 3 4 5 4 3 2 1

printf("(iii)\t");

for (i = 1; i <= 5; i++) {

printf("%d\t", i);

for (i = 4; i >= 1; i--) {

printf("%d\t", i);
}

printf("\n");

// (iv) 5 4 3 2 1 2 3 4 5

printf("(iv)\t");

for (i = 5; i >= 1; i--) {

printf("%d\t", i);

for (i = 2; i <= 5; i++) {

printf("%d\t", i);

printf("\n");

return 0;

Question 3
#include <stdio.h>

int main() {

int arr[10] = {1, 2, 1, 3, 4, 2, 1, 5, 6, 7};

int i, j;

int count;

for (i = 0; i < 10; i++) {

count = 1;

for (j = 0; j < i; j++) {


if (arr[i] == arr[j]) {

count = 0;

break;

if (count > 0) {

for (j = i + 1; j < 10; j++) {

if (arr[i] == arr[j]) {

count++;

if (count > 1) {

printf("Data is %d and duplicate time is %d \n", arr[i], count);

return 0;

Question 4
#include <stdio.h>

#include <stdlib.h>

int main() {
int i=1;

int opt=0;

while(opt==0) {

i*=2;

printf("%4d",i);

if(i==512) {

opt = 1;

return 0;

Question 5
#include <stdio.h>

#include <stdbool.h>

bool is_prime(int num) {


if (num < 2) return false;

for (int i = 2; i * i <= num; i++) {

if (num % i == 0) return false;

return true;

int main() {

int count = 0;

printf("Prime numbers between 2 and 100 are:\n");

for (int i = 2; i <= 100; i++) {

if (is_prime(i)) {

printf("%d ", i);

count++;

printf("\nTotal number of prime numbers between 2 and 100: %d\n", count);

return 0;

Question 6
//Quesition 6

#include <stdio.h>
int main() {

double balance = 0.0; // Initial balance is $0.00

double deposit = 50.0; // Monthly deposit is $50.00

double interest_rate = 0.01; // Monthly interest rate is 1%

int months = 12; // Number of months in a year

for (int i = 0; i < months; i++) {

balance += deposit; // Add the deposit to the balance

balance += balance * interest_rate; // Add the interest to the balance

printf("Month %d: $%.2f\n", i + 1, balance);

printf("\nFinal balance after one year: $%.2f\n", balance);

return 0;

Question 7
#include <stdio.h>

struct phone {

int area_code;

int exchange;

int number;

};
int main() {

struct phone my_number = {161, 892, 9999};

struct phone your_number;

printf("Enter your area code, exchange, and number: ");

scanf("%d %d %d", &your_number.area_code, &your_number.exchange, &your_number.number);

printf("My number is (%d) %d-%d\n", my_number.area_code, my_number.exchange,


my_number.number);

printf("Your number is (%d) %d-%d\n", your_number.area_code, your_number.exchange,


your_number.number);

return 0;

You might also like