0% found this document useful (0 votes)
1 views15 pages

c Programming

Uploaded by

bossrk586
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)
1 views15 pages

c Programming

Uploaded by

bossrk586
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/ 15

Great.

I’ll write copy-ready model answers in TU exam style for the


two additional papers you shared:

A) C-Programming (CACS151) — Group B (Q11–Q17: 5 marks


each) and Group C (Q18–Q20: 10 marks each).
B) C-Programming (another set, 2021) — Group B (8 short
questions, 5 or 2+3 as shown) and Group C (Q9–Q11: 10 marks
each).

I’ll number them exactly as in your images and tailor to the mark
splits shown.

===================================================
==
PAPER A: C-Programming (CACS151), 2018

Group B [6×5=30]

Q11. What is software process model? Differentiate between


cohesion and coupling in programming. [1+4]

Definition:

 A software process model is a structured representation of the


activities, tasks, and deliverables followed to develop and
maintain software (e.g., Waterfall, Spiral, Iterative).

Cohesion vs Coupling (any 4 crisp points):

 Meaning: Cohesion = degree to which elements inside a module


belong together; Coupling = degree of interdependence
between modules.
 Goal: High cohesion is desirable; Low coupling is desirable.
 Effect: Higher cohesion improves clarity and reuse; Higher
coupling increases ripple effects of changes.
 Measurement: Cohesion types (functional, sequential, logical…
from high to low); Coupling types (data, stamp, control,
common, content… from low to high).
 Maintenance: High cohesion & low coupling reduce
maintenance cost.

Q12. Define keyword and identifiers. Explain rules for defining


valid identifiers. [2+3]

Definitions:

 Keyword: A reserved word with predefined meaning in C (e.g.,


int, if, return); cannot be used as identifiers.
 Identifier: A name given to program elements (variables,
functions, arrays) defined by the programmer.

Rules (any 5 clear rules):

 Consists of letters (A–Z,a–z), digits (0–9), and underscore;


must start with a letter or underscore.
 Case-sensitive (sum and Sum are different).
 No spaces or special symbols other than underscore.
 Cannot be a keyword.
 Length may be implementation-dependent; use meaningful
short names.
 Should not start with a digit.

Q13. List the operators used in C on the basis of utility. Explain the
concept of bitwise operator. [2+3]

Classification (utility-wise):

 Arithmetic (+, −, *, /, %), Relational (<, >, <=, >=, ==, !=),
Logical (&&, ||, !), Bitwise (&, |, ^, ~, <<, >>), Assignment (=,
+=, …), Increment/Decrement (++/−−), Conditional (?:), Misc
(sizeof, comma, address-of &, dereference *, member . and ->).
Bitwise operators (concept + examples):

 Operate at bit-level on integers.


 AND &: 5&3 = 0101&0011 = 0001 (1).
 OR |: 5|2 = 0101|0010 = 0111 (7).
 XOR ^: 5^3 = 0110 (6) — toggles bits.
 NOT ~: ~5 flips bits (implementation-dependent with two’s
complement).
 Left shift << and Right shift >>: 5<<1 = 10; 8>>2 = 2.
 Use cases: masking, setting/clearing bits, fast multiply/divide
by powers of two, flags.

Q14. Differentiate between while loop and do while loop. Write a C


program to find input number is prime or composite. [2+3]

Differences (any 4):

 Entry vs exit control: while checks before body; do-while


checks after.
 Execution: while may execute 0 times; do-while executes at
least once.
 Syntax: while(condition){...}; do{...}while(condition);
 Semicolon: do-while ends with semicolon; while loop does not.
 Use-case: do-while suitable for menu-driven tasks.

Program (concise):

c
#include <stdio.h>
int main(void){
int n,i,flag=1;
scanf("%d",&n);
if(n<2){ printf("Composite\n"); return 0; }
for(i=2;i*i<=n;i++){
if(n%i==0){ flag=0; break; }
}
printf(flag?"Prime\n":"Composite\n");
return 0;
}

Q15. What is DMA? Write a program to find the largest and


smallest number in a list of N numbers using DMA. [1+4]

Definition:

 DMA (Dynamic Memory Allocation) allocates memory at


runtime from the heap using functions like malloc, calloc,
realloc, free in C.

Program using DMA:

c
#include <stdio.h>
#include <stdlib.h>
int main(void){
int n,i; int *a; int min,max;
scanf("%d",&n);
a = (int*)malloc(n*sizeof(int));
if(!a) return 0;
for(i=0;i<n;i++) scanf("%d",&a[i]);
min=max=a[0];
for(i=1;i<n;i++){
if(a[i]<min) min=a[i];
if(a[i]>max) max=a[i];
}
printf("Min=%d Max=%d\n",min,max);
free(a);
return 0;
}
Q16. What is difference between binary file and text file? Write a C
program to write some text "Welcome to BCA program" in a file
test.text. [2+3]

Differences:

 Storage: Text stores characters (human-readable) with newline


translation; Binary stores exact byte representation.
 I/O functions: Text uses fprintf/fscanf; Binary uses
fread/fwrite.
 Size/Speed: Binary is compact and faster; Text is larger and
slower due to conversions.
 Portability: Text is more portable across systems; Binary is
system-dependent.

Program:

c
#include <stdio.h>
int main(void){
FILE *fp = fopen("test.text","w");
if(!fp) return 0;
fputs("Welcome to BCA program", fp);
fclose(fp);
return 0;
}

Q17. Explain any four graphics functions in C. Write a program to


draw two concentric circles with center (50,50) and radii 75 and 125.
[2+3]

Four common BGI functions (as used in TU’s Turbo C/graphics.h


context):

 initgraph(&gd,&gm,path): initialize graphics mode.


 circle(x, y, r): draw circle with center (x,y) and radius r.
 line(x1,y1,x2,y2): draw line segment.
 rectangle(x1,y1,x2,y2): draw rectangle.
 setcolor(color), setbkcolor(color), putpixel(x,y,color) —
mention any four.

Program (BGI style):

c
#include <graphics.h>
#include <conio.h>
int main(void){
int gd=DETECT, gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
circle(50,50,75);
circle(50,50,125);
getch();
closegraph();
return 0;
}

Group C [2×10=20]

Q18. What is one dimensional array? How is it initialized? Write a


C program to find the sum of two matrix of order m×n. [1+1+8]

Definition:

 A one-dimensional array is a linear collection of elements of


the same type stored contiguously and accessed by a single
index (e.g., int a).benchpartner

Initialization:

 At declaration: int a={1,2,3,4,5}; or partial int a={1,2};


remaining become 0. Runtime via loop.bcapoint

Program: matrix sum m×n


c
#include <stdio.h>
int main(void){
int m,n,i,j;
scanf("%d%d",&m,&n);
int A[m][n], B[m][n], C[m][n];
for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&A[i][j]);
for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&B[i][j]);
for(i=0;i<m;i++) for(j=0;j<n;j++) C[i][j]=A[i][j]+B[i][j];
for(i=0;i<m;i++){
for(j=0;j<n;j++) printf("%d ",C[i][j]);
printf("\n");
}
return 0;
}

Q19. Define structure and union? Write a C program using


structure that reads the records of 35 students with members roll,
name, address and marks and display the record of students who
have obtained greater than 250 marks. [2+8]

Definitions:

 Structure: User-defined type that groups different data types


under one name; members occupy distinct memory.
 Union: Like structure but all members share the same memory
location; size equals largest member; only one member valid at
a time.

Program:

c
#include <stdio.h>
struct Student{
int roll;
char name;
char address;
int marks; /* total out of 300, for example */
};
int main(void){
struct Student s;
int i;
for(i=0;i<35;i++){
/* example input: roll name address marks */
scanf("%d%39s%59s
%d",&s[i].roll,s[i].name,s[i].address,&s[i].marks);
}
for(i=0;i<35;i++){
if(s[i].marks>250){
printf("%d %s %s %d\
n",s[i].roll,s[i].name,s[i].address,s[i].marks);
}
}
return 0;
}

Q20. What is function? List its advantages. Explain the concept of


function call by value and function call by reference with example.
[1+2+7]

Definition:

 A function is a self-contained block of code that performs a


specific task and may return a value.

Advantages (any 4): modularity, reusability, easy testing/debugging,


abstraction, reduced code size, teamwork.

Call by value vs reference with examples:

 Call by value: Actual argument’s value is copied to function


parameters; changes do not affect caller.
c
#include <stdio.h>
void increment(int x){ x++; } /* caller variable unaffected */
int main(void){ int a=5; increment(a); printf("%d",a); return 0; }

 Call by reference: Function receives address; changes reflect


back.

c
#include <stdio.h>
void swap(int *x,int *y){ int t=*x; *x=*y; *y=t; }
int main(void){ int a=3,b=4; swap(&a,&b); printf("%d %d",a,b);
return 0; }

===================================================
==
PAPER B: C-Programming (CACS151), 2021

Group B [6×5=30] — I’ll label as per your scanned sheet numbers.

Q2. Write a C program to generate the following output using


loop.bcapoint
Pattern:
10101
01010
10101
01010
101

Program (prints 5 rows as seen):

c
#include <stdio.h>
int main(void){
int i,j,n=5;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%d ", (i+j)%2==0 ? 1 : 0);
}
printf("\n");
}
return 0;
}

Q3. How will you define pointer? Write a program that illustrates
how pointer variable changes the value of normal variable. [2+3]

Definition:

 A pointer is a variable that stores the memory address of


another variable.

Program:

c
#include <stdio.h>
int main(void){
int a=10; int *p=&a;
*p = *p + 5; /* changes a through pointer */
printf("%d\n", a); /* outputs 15 */
return 0;
}

Q4. Write a C program to calculate sum of the natural number up


to N using recursive function.bcapoint

c
#include <stdio.h>
long long sumN(long long n){ return (n==0)?0:n+sumN(n-1); }
int main(void){ long long n; scanf("%lld",&n); printf("%lld\
n",sumN(n)); return 0; }
Q5. Write a C program to calculate following expression: 5x√(y^2 +
5).bcapoint

c
#include <stdio.h>
#include <math.h>
int main(void){
double x,y,ans;
scanf("%lf%lf",&x,&y);
ans = 5.0*x*sqrt(y*y + 5.0);
printf("%.3f\n",ans);
return 0;
}

Q6. Write a C program to copy contents of student.txt file into


another file called info.txt.bcapoint

c
#include <stdio.h>
int main(void){
FILE *fs=fopen("student.txt","r");
FILE *ft=fopen("info.txt","w");
int ch;
if(!fs || !ft) return 0;
while((ch=fgetc(fs))!=EOF) fputc(ch,ft);
fclose(fs); fclose(ft);
return 0;
}

Q7. Why do you use DMA instead of array? Explain DMA with
suitable example. [2+3]

Answer:
 DMA preferred when size is known only at runtime or may
grow/shrink; arrays have fixed size at compile time and may
waste/overflow memory.
 DMA enables efficient heap use via malloc/calloc/realloc/free.

Example:

c
#include <stdio.h>
#include <stdlib.h>
int main(void){
int n,*a,i; scanf("%d",&n);
a=(int*)malloc(n*sizeof(int));
for(i=0;i<n;i++) scanf("%d",&a[i]);
/* process … */
free(a);
return 0;
}

Q8. Write a C program to generate following output using graphics


functions.bcapoint
Since the exact shape wasn’t clear except a “BCA” ellipse/circle,
here’s a standard BGI example drawing a circle and printing text
“BCA” inside:

c
#include <graphics.h>
#include <conio.h>
int main(void){
int gd=DETECT, gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
circle(200,150,80);
outtextxy(180,150,"BCA");
getch();
closegraph();
return 0;
}

(If a different figure is required, share the exact shape; I’ll adjust
coordinates and functions.)

Group C [2×10=20]

Q9. Write a C program to store the player name, runs scored,


wickets taken of 20 cricketers using structure along with pointer
then arrange the players in order of maximum wickets to minimum
wickets they had taken.benchpartner

c
#include <stdio.h>
#include <string.h>
#define N 20
struct Player{ char name; int runs; int wickets; };
int cmp(const void *a,const void *b){
const struct Player *p=a,*q=b;
return (q->wickets - p->wickets); /* descending */
}
int main(void){
struct Player t[N], *p=t;
int i;
for(i=0;i<N;i++){
scanf("%39s%d%d", p[i].name, &p[i].runs, &p[i].wickets);
}
qsort(t,N,sizeof(t),cmp);
for(i=0;i<N;i++){
printf("%-20s %4d %3d\n", t[i].name, t[i].runs, t[i].wickets);
}
return 0;
}

Q10. Write a C program to generate following series using function:


Sum = 1 + x/1! + x^2/2! + x^3/3! + ... + x^n/n!benchpartner
c
#include <stdio.h>
double power(double x,int n){ double p=1; for(int i=1;i<=n;i++)
p*=x; return p; }
double fact(int n){ double f=1; for(int i=2;i<=n;i++) f*=i; return f; }
int main(void){
int n; double x,sum=1.0;
scanf("%lf%d",&x,&n);
for(int k=1;k<=n;k++) sum += power(x,k)/fact(k);
printf("%.6f\n",sum);
return 0;
}

Q11. Define SDLC. Explain software process models. [2+8]

Definition:

 SDLC (Software Development Life Cycle) is a framework


defining phases to build, deliver, and maintain software:
requirement analysis, design, implementation, testing,
deployment, maintenance.

Process models (brief, TU-style):

 Waterfall: linear phases; simple to manage; poor for changing


requirements.
 V-Model: verification/validation mapping; testing planned
parallel to development.
 Incremental/Iterative: deliver in increments; feedback-driven;
improved risk handling.
 Spiral: risk-driven cycles combining prototyping and
waterfall; good for large, high-risk projects.
 Prototyping: build quick prototype to refine requirements;
then engineer final system.
 Agile (Scrum/Kanban): short iterations, customer
collaboration, continuous delivery.
Key comparison points:

 Requirement volatility tolerance, risk management, customer


involvement, documentation level, delivery cadence.

===================================================
==

You might also like