SlideShare a Scribd company logo
Lab Assignment 3: Array and Structures: C Programming
CS-153 Computer Programming Lab
Autumn Semester, 2016, IIT Indore
Date: 17-08-16
Note: Write following programs in C language. Also note that this assignment will be evaluated by
TA’s in the upcoming labs of next week (22-08-16 onward) for each batch.
1. Write a program to compute the frequencies of all distinct numbers that appear in the array of size N.
Read N and the actual numbers in the array from the keyboard before you compute the frequency.
2. Write a program to display Pascal's triangle. Pascal's triangle represents the binomial coefficients*. The
first few rows of Pascal's triangle are displayed below. Observe how a row is related to the row above
it.
Extra Point: How many arrays did you use? Try solving the problem with just one array.
* Example of binomial coefficient for 6th
row is (x + y)5
= 1 x5
+ 5 x4
y + 10 x3
y2
+ 10 x2
y3
+ 5 x y4
+ 1 y5
3. Write a program to produce the following output:
A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
4. Create a structure to specify data on students given below: Roll number, Name, Department, Course,
Year of joining Assume that there are not more than 450 students in the institute.
5. Create a structure to specify data of customers in a bank. The data to be stored is: Account number,
Name, Balance in account. Assume maximum of 200 customers in the bank.
#include<stdio.h>
#include<conio.h>
int main(){
int n, t, i, j, arr[30],len, halflen,flag=0,count=0;
printf("Enter number of elements to insert in an array:n");
scanf("%d",&len);
printf("Enter elements to insert in an array:n");
for(i=0;i<len;i++){
scanf("%d",&t);
arr[i]=t;
}
printf("n");
/*****************************/
for(i=0;i<len;i++){ //loop for pass 1 to len
count=1; //again initialize the count variable with 1
for(j=i+1;j<=len-1;j++){
if(arr[i]==arr[j] && arr[i]!='0'){ //if same value of arr[i] find at index 'j' and it is
not null then
count++; //increment the count of frequency for the value
arr[j]='0'; //store null value to arr[j]
}
}
if(arr[i]!='0'){ //if value of arr[i] is not null then
printf("%d is %d times.n",arr[i],count); //print the value if arr[i] and it frequency
count
}
}
/*****************************/
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
int main()
{
int array[10][10];
int i, j, k, rows;
printf("Enter the number of rowsn");
scanf("%d",&rows);
for(i=1; i<=rows; i++) //create array of size rows
{
for(j=1; j<=i; j++) //count of the values in a row will be same as the index 'i'
of the rows
{
if(j==1||j==i) //if it is first value of a row or count of the values in a row
matches with the row index 'i'
{
array[i][j]=1; //then store value 1 in array[i][j]
}
else
{
array[i][j]=array[i-1][i-j]+array[i-1][i-j+1]; //else sum the two values on
above row of
}
}
}
for(i=1; i<=rows; i++) //print array of size rows
{
for(k=1; k<=rows-i; k++) //adjust the spaces between printed values for the
index 1 to row-i
{
printf(" ");
}
for(j=1; j<=i; j++) //print values form the index 1 to i
{
printf("%d ",array[i][j]);
}
printf("n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
main() {
int i,j,k,l;
for(i=71;i>=65;i--) {
/* loop for printing ascending letters */
for(j=65;j<=i;j++) {
printf("%c ",j);
}
/* loop for making a space between patterns */
for(k=i+1;k<=71;k++) {
if(k==71)
printf(" ");
if(k<71)
printf(" ");
}
/* loop to print descending letters */
for(l=i;l>=65;l--) {
if(l==71) { /* to skip printing 'G' twice */
continue;
}
printf("%c ",l);
}
printf("n");
}
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#define N 450
struct students {
int rlnm;
char name[25];
char dept[25]; /* structure defined outside of main(); */
char course[25];
int year;
};
main() {
/* main() */
struct students s[N];
int i, ch;
/* taking input of 450 students in an array of structure */
for (i = 0; i < N; i++) {
printf(" Enter data of student %dtttttotal students: %dn", i + 1, N);
printf("****************************nn");
printf("enter rollnumber: ");
scanf("%d", & s[i].rlnm);
printf("nnenter name: ");
scanf(" %s", & s[i].name);
printf("nnenter department: ");
scanf("%s", & s[i].dept);
printf("nnenter course: ");
scanf("%s", & s[i].course);
printf("nnenter year of joining: ");
scanf("%d", & s[i].year);
}
getch();
}
#include<stdio.h>
#include<conio.h>
#define N 200
struct bank {
int acn;
char name[20];
int bal; /* defined out of main() */
};
void main() {
struct bank b[N];
int i, ch, lw = 100, ch2, ac, am;
for (i = 0; i < N; i++) {
/* inputting customer data */
printf("tEnter information of customers n");
printf("t******************************nn");
printf("enter account no.: ");
scanf("%d", & b[i].acn);
printf("nnenter customer name: ");
scanf("%s", & b[i].name);
printf("nnenter balance: ");
scanf("%d", & b[i].bal);
}
getch();
}

More Related Content

PDF
LR Parsing
PDF
C- Programming Assignment practice set 2 solutions
PPT
Polygon Fill
PPT
Z buffer
PDF
I.BEST FIRST SEARCH IN AI
PPT
hidden surface elimination using z buffer algorithm
PPTX
Chapter 5 boolean algebra
PDF
Digital Image Processing: Digital Image Fundamentals
LR Parsing
C- Programming Assignment practice set 2 solutions
Polygon Fill
Z buffer
I.BEST FIRST SEARCH IN AI
hidden surface elimination using z buffer algorithm
Chapter 5 boolean algebra
Digital Image Processing: Digital Image Fundamentals

What's hot (20)

PPT
computer graphics
PPT
Fill area algorithms
PPTX
Reflection transformation
PPTX
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
PPT
Clipping Algorithm In Computer Graphics
PPTX
Compiler Design LR parsing SLR ,LALR CLR
PDF
AI_ 3 & 4 Knowledge Representation issues
PPTX
Dynamic memory allocation
PPT
Midpoint circle algo
DOC
Network lab manual
PPTX
Parsing LL(1), SLR, LR(1)
PPTX
Learn C# Programming - Encapsulation & Methods
PPTX
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
PPT
Seed filling algorithm
PPTX
Cohen sutherland line clipping
PDF
Binary tree
PDF
Reinforcement Learning Tutorial | Edureka
PDF
Unit3:Informed and Uninformed search
PPTX
Lecture 15 monkey banana problem
PPTX
Computer Graphics: Visible surface detection methods
computer graphics
Fill area algorithms
Reflection transformation
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
Clipping Algorithm In Computer Graphics
Compiler Design LR parsing SLR ,LALR CLR
AI_ 3 & 4 Knowledge Representation issues
Dynamic memory allocation
Midpoint circle algo
Network lab manual
Parsing LL(1), SLR, LR(1)
Learn C# Programming - Encapsulation & Methods
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Seed filling algorithm
Cohen sutherland line clipping
Binary tree
Reinforcement Learning Tutorial | Edureka
Unit3:Informed and Uninformed search
Lecture 15 monkey banana problem
Computer Graphics: Visible surface detection methods
Ad

Similar to C- Programming Assignment 3 (20)

DOCX
Data Structure Project File
DOCX
PPT
Array THE DATA STRUCTURE. ITS THE STRUCT
PPT
C Language Unit-4
PPT
Unit4
PPT
array.ppt
DOC
Basic c programs updated on 31.8.2020
DOC
PDF
C- Programming Assignment 4 solution
PDF
Lab program 1234567891234567891234567891
PDF
Complete Lab 123456789123456789123456789
PDF
lab.123456789123456789123456789123456789
 
PPTX
C_Arrays.pptx
DOCX
Data Structures Using C Practical File
PPT
Chapter2
PPT
Chapter2
PPT
Arrays and structures
PPT
Basics of Data structure using C describing basics concepts
PDF
Array in C.pdf
Data Structure Project File
Array THE DATA STRUCTURE. ITS THE STRUCT
C Language Unit-4
Unit4
array.ppt
Basic c programs updated on 31.8.2020
C- Programming Assignment 4 solution
Lab program 1234567891234567891234567891
Complete Lab 123456789123456789123456789
lab.123456789123456789123456789123456789
 
C_Arrays.pptx
Data Structures Using C Practical File
Chapter2
Chapter2
Arrays and structures
Basics of Data structure using C describing basics concepts
Array in C.pdf
Ad

More from Animesh Chaturvedi (20)

PDF
Cloud Platforms & Frameworks
PDF
Cloud platforms and frameworks
PDF
Cloud service lifecycle management
PDF
Graph Analytics and Complexity Questions and answers
PDF
Advance Systems Engineering Topics
PDF
P, NP, NP-Complete, and NP-Hard
PDF
System Development Life Cycle (SDLC)
PDF
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
PDF
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
PDF
C - Programming Assignment 1 and 2
PDF
System requirements engineering
PDF
Informatics systems
PDF
Introduction to Systems Engineering
PDF
Big Data Analytics and Ubiquitous computing
PDF
Cloud Platforms and Frameworks
PDF
Cloud Service Life-cycle Management
PDF
Push Down Automata (PDA)
PDF
Pumping Lemma and Regular language or not?
PDF
Regular language and Regular expression
PDF
Pattern detection in mealy machine
Cloud Platforms & Frameworks
Cloud platforms and frameworks
Cloud service lifecycle management
Graph Analytics and Complexity Questions and answers
Advance Systems Engineering Topics
P, NP, NP-Complete, and NP-Hard
System Development Life Cycle (SDLC)
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
C - Programming Assignment 1 and 2
System requirements engineering
Informatics systems
Introduction to Systems Engineering
Big Data Analytics and Ubiquitous computing
Cloud Platforms and Frameworks
Cloud Service Life-cycle Management
Push Down Automata (PDA)
Pumping Lemma and Regular language or not?
Regular language and Regular expression
Pattern detection in mealy machine

Recently uploaded (20)

PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
cuic standard and advanced reporting.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Big Data Technologies - Introduction.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
KodekX | Application Modernization Development
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Advanced Soft Computing BINUS July 2025.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Sensors and Actuators in IoT Systems using pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
cuic standard and advanced reporting.pdf
Chapter 3 Spatial Domain Image Processing.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Big Data Technologies - Introduction.pptx
Review of recent advances in non-invasive hemoglobin estimation
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Reach Out and Touch Someone: Haptics and Empathic Computing
“AI and Expert System Decision Support & Business Intelligence Systems”
KodekX | Application Modernization Development
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Advanced Soft Computing BINUS July 2025.pdf
Understanding_Digital_Forensics_Presentation.pptx
Sensors and Actuators in IoT Systems using pdf

C- Programming Assignment 3

  • 1. Lab Assignment 3: Array and Structures: C Programming CS-153 Computer Programming Lab Autumn Semester, 2016, IIT Indore Date: 17-08-16 Note: Write following programs in C language. Also note that this assignment will be evaluated by TA’s in the upcoming labs of next week (22-08-16 onward) for each batch. 1. Write a program to compute the frequencies of all distinct numbers that appear in the array of size N. Read N and the actual numbers in the array from the keyboard before you compute the frequency. 2. Write a program to display Pascal's triangle. Pascal's triangle represents the binomial coefficients*. The first few rows of Pascal's triangle are displayed below. Observe how a row is related to the row above it. Extra Point: How many arrays did you use? Try solving the problem with just one array. * Example of binomial coefficient for 6th row is (x + y)5 = 1 x5 + 5 x4 y + 10 x3 y2 + 10 x2 y3 + 5 x y4 + 1 y5 3. Write a program to produce the following output: A B C D E F G F E D C B A A B C D E F F E D C B A A B C D E E D C B A A B C D D C B A A B C C B A A B B A A A 4. Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the institute. 5. Create a structure to specify data of customers in a bank. The data to be stored is: Account number, Name, Balance in account. Assume maximum of 200 customers in the bank.
  • 2. #include<stdio.h> #include<conio.h> int main(){ int n, t, i, j, arr[30],len, halflen,flag=0,count=0; printf("Enter number of elements to insert in an array:n"); scanf("%d",&len); printf("Enter elements to insert in an array:n"); for(i=0;i<len;i++){ scanf("%d",&t); arr[i]=t; } printf("n"); /*****************************/ for(i=0;i<len;i++){ //loop for pass 1 to len count=1; //again initialize the count variable with 1 for(j=i+1;j<=len-1;j++){ if(arr[i]==arr[j] && arr[i]!='0'){ //if same value of arr[i] find at index 'j' and it is not null then count++; //increment the count of frequency for the value arr[j]='0'; //store null value to arr[j] } } if(arr[i]!='0'){ //if value of arr[i] is not null then printf("%d is %d times.n",arr[i],count); //print the value if arr[i] and it frequency count } } /*****************************/ getch(); return 0; }
  • 3. #include<stdio.h> #include<conio.h> int main() { int array[10][10]; int i, j, k, rows; printf("Enter the number of rowsn"); scanf("%d",&rows); for(i=1; i<=rows; i++) //create array of size rows { for(j=1; j<=i; j++) //count of the values in a row will be same as the index 'i' of the rows { if(j==1||j==i) //if it is first value of a row or count of the values in a row matches with the row index 'i' { array[i][j]=1; //then store value 1 in array[i][j] } else { array[i][j]=array[i-1][i-j]+array[i-1][i-j+1]; //else sum the two values on above row of } } } for(i=1; i<=rows; i++) //print array of size rows { for(k=1; k<=rows-i; k++) //adjust the spaces between printed values for the index 1 to row-i { printf(" "); } for(j=1; j<=i; j++) //print values form the index 1 to i { printf("%d ",array[i][j]); } printf("n"); } getch(); }
  • 4. #include<stdio.h> #include<conio.h> main() { int i,j,k,l; for(i=71;i>=65;i--) { /* loop for printing ascending letters */ for(j=65;j<=i;j++) { printf("%c ",j); } /* loop for making a space between patterns */ for(k=i+1;k<=71;k++) { if(k==71) printf(" "); if(k<71) printf(" "); } /* loop to print descending letters */ for(l=i;l>=65;l--) { if(l==71) { /* to skip printing 'G' twice */ continue; } printf("%c ",l); } printf("n"); } getch(); return 0; }
  • 5. #include<stdio.h> #include<conio.h> #define N 450 struct students { int rlnm; char name[25]; char dept[25]; /* structure defined outside of main(); */ char course[25]; int year; }; main() { /* main() */ struct students s[N]; int i, ch; /* taking input of 450 students in an array of structure */ for (i = 0; i < N; i++) { printf(" Enter data of student %dtttttotal students: %dn", i + 1, N); printf("****************************nn"); printf("enter rollnumber: "); scanf("%d", & s[i].rlnm); printf("nnenter name: "); scanf(" %s", & s[i].name); printf("nnenter department: "); scanf("%s", & s[i].dept); printf("nnenter course: "); scanf("%s", & s[i].course); printf("nnenter year of joining: "); scanf("%d", & s[i].year); } getch(); }
  • 6. #include<stdio.h> #include<conio.h> #define N 200 struct bank { int acn; char name[20]; int bal; /* defined out of main() */ }; void main() { struct bank b[N]; int i, ch, lw = 100, ch2, ac, am; for (i = 0; i < N; i++) { /* inputting customer data */ printf("tEnter information of customers n"); printf("t******************************nn"); printf("enter account no.: "); scanf("%d", & b[i].acn); printf("nnenter customer name: "); scanf("%s", & b[i].name); printf("nnenter balance: "); scanf("%d", & b[i].bal); } getch(); }