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

Programming Lab Report 4

This document contains a lab manual for a computer fundamentals and programming course. It includes two programming assignments - the first to copy elements from one array into another, and the second to count duplicate elements in an array. For each assignment, it provides sample input/output, the C code to solve the problem, and screenshots of running the program.

Uploaded by

Safwan Nasir
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)
70 views

Programming Lab Report 4

This document contains a lab manual for a computer fundamentals and programming course. It includes two programming assignments - the first to copy elements from one array into another, and the second to count duplicate elements in an array. For each assignment, it provides sample input/output, the C code to solve the problem, and screenshots of running the program.

Uploaded by

Safwan Nasir
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

Lab Manual

Fall-2020

Computer Fundamentals and Programming

Submitted by: SAFWAN NASIR


MECHANICAL DEPARTMENT
SAFWAN NASIR
CF-2 GROUP 3 MS-20-IM-500594
Report: Lab 3 “Computer Fundamentals”

Write a program in C to copy the elements of one array into another


array.

Sample Output :

Input the number of elements to be stored in the array :3

Input 3 elements in the array :

element - 0 : 15

element - 1 : 10

element - 2 : 12

Expected Output :

The elements stored in the first array are :

15 10 12 The elements copied into the second array are :

15 10 12

CODE:
#include <stdio.h>

#include <stdlib.h>

int main()

1|Page
{

int arr1[100],arr2[100],element,m_element;

printf ("Input the number of elements to be stored in the array :");

scanf("%d",&m_element);

printf ("Input %d elements in the array : \n",m_element);

for (element=0;element<m_element;element++)

printf ("element - %d : ",element);

scanf("%d",&arr1[element]);

arr2[element]=arr1[element];

printf ("The elements stored in the first array are : \n");

for (element=0;element<m_element;element++)

printf("%d\t",arr1[element]);

printf ("\nThe elements stored in the second array are : \n");

for (element=0;element<m_element;element++)

printf("%d\t",arr2[element]);

getchar();getchar();

return 0;

2|Page
}

Figure 1: Screenshot of the above program.

3|Page
Figure 2: Here is shown the .exe file of the above program.

Within Lab Task 2

Write a program in C to count a total number of duplicate elements


in an array.

Sample Output :

Input the number of elements to be stored in the array :3

Input 3 elements in the array :

element - 0 : 5

element - 1 : 1

element - 2 : 1

Expected Output :

Total number of duplicate elements found in the array is : 1


CODE:
#include <stdio.h>

#include <stdlib.h>

int main()

int arr1[100],element,m_element,count=0,i;

4|Page
printf ("Input the number of elements to be stored in the array :");

scanf("%d",&m_element);

printf ("Input %d elements in the array : \n",m_element);

for (element=0;element<m_element;element++)

printf ("element - %d : ",element);

scanf("%d",&arr1[element]);

for (element=0;element<m_element;element++)

for (i=0;i<m_element;i++)

if (arr1[element]==arr1[i] && element!=i && element<i)

count++;

break;

printf ("Total number of duplicate elements found in the array is : %d ",count);

5|Page
getchar();getchar();

return 0;

Figure 3: Screenshot of the above program.

6|Page
Figure 4: Here is shown the .exe file of the above program.

7|Page

You might also like