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

20BCE0611ADVCLAD5

This document contains solutions to 8 questions on C programming and shell scripting. It includes code snippets and output for each question. The questions cover topics like arrays, file handling, command line arguments, process IDs, identifying vowels, date parsing and more.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

20BCE0611ADVCLAD5

This document contains solutions to 8 questions on C programming and shell scripting. It includes code snippets and output for each question. The questions cover topics like arrays, file handling, command line arguments, process IDs, identifying vowels, date parsing and more.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

CSE2010 ADVANCED C PROGRAMMING

NAME: MADHULIKA DARBHA

REG. NO.: 20BCE0611

Q1: Write a C program to delete the elements at the given position(s) in an array without using
second array by passing the array to a function and display the resultant array in display function.

CODE:

#include <stdio.h>

#include <conio.h>

int main ()

int arr[50];

int pos, i, num;

printf (" \n Enter the number of elements in an array: \n ");

scanf (" %d", &num);

printf (" \n Enter %d elements in array: \n ", num);

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

{ printf (" arr[%d] = ", i);

scanf (" %d", &arr[i]);

printf( " Define the position of the array element where you want to delete: \n ");

scanf (" %d", &pos);

if (pos >= num+1)

printf (" \n Deletion is not possible in the array.");

else

for (i = pos - 1; i < num -1; i++)

arr[i] = arr[i+1];
}

printf (" \n The resultant array is: \n");

for (i = 0; i< num - 1; i++)

printf (" arr[%d] = ", i);

printf (" %d \n", arr[i]);

return 0;

OUTPUT:

2. Write a C program to get 10 VIT registration numbers and store only the first year student’s
registration number into a file. Also retrieve the second last registration number from the file.

CODE:

#include <stdio.h>

int main(){

char regno [9] [10];

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

printf("Enter reg no. : ");

scanf("%s", regno[i]);
}

FILE *fp; fp = fopen("1st Year Reg No", "w+");

int a = 0;

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

if (regno[i][0] == '2' && regno[i] [1] == '1'){

fprintf(fp,"%s\n", regno[i]);

a++;

fclose(fp);

OUTPUT:

3. Write a C program using command line arguments to get 5 input numbers and calculate the total
number of odd numbers except ‘5’(if present), and the total number of even numbers except ‘2’ (if
present).

CODE:

#include <stdio.h>

int main(int argc, char **argv)

{
int odd=0,even=0;

for (int i = 1; i < argc; ++i)

int a = atoi(argv[i]);

if(a%2==0 && a!=2)

even++;

else if(a%2==1 && a!=5)

odd++;

printf("odd numbers %d\n",odd);

printf("even numbers %d\n",even);

return 0;

OUTPUT:

4. a) Write a program to know the PID and PPID of the calling process.

CODE:

#include<stdio.h>

#include<unistd.h>

int main(){

int p_id,p_pid;

p_id = getpid();

p_pid = getppid();

printf("Process ID: %d\n", p_id);

printf("parent process ID: %d\n", p_pid);

return 0;

OUTPUT:
b) Write a shell script to check the smallest and greatest number among the given 3 numbers.

CODE:

!/bin/bash

echo "enter size of an array"

read n

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

do

echo " enter $((i+1)) number"

read nos[$i]

done

echo "number entered are"

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

do

echo ${nos[$i]}

done

small=${nos[0]}

greatest=${nos[0]}

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

do

if [ ${nos[$i]} -lt $small ]; then

small=${nos[$i]}

elif [ ${nos[$i]} -gt $greatest ]; then

greatest=${nos[$i]}

fi

done

echo "smallest number in an array is $small"

echo "greatest number in an array is $greatest"

OUTPUT:
5. a) write a shell script to identify the vowels by reading a character from user using switch case

CODE:

echo "Enter any character"

read ch

case $ch in

"a") echo "it is a vowel.";;

"e") echo "it is a vowel.";;

"i") echo "it is a vowel.";;

"o") echo "it is a vowel.";;

"u") echo "it is a vowel.";;

*) echo "it is not a vowel."

Esac

OUTPUT:

b) Write a shell script to perform the below operations

i) To parse date and time

ii) To display the last updated file

iii) To print the number of files or directories

CODE:

#!/bin/bash

echo "Date : "


date

echo "Last updated file : "

-r q5_b.sh

echo "Number of files : "

ls| wc -l

OUTPUT:

6. a)Write a shell script to concatenate two strings

b) Write a shell script to remove the duplicate lines from files.

CODE:

read a b

a+=$b

echo $a

OUTPUT:

7. Display all the options and descriptions which can be used along with PS command with example

CODE:

Ps

Ps -f

Ps -a

Ps -x

OUTPUT:
8. Discuss about the network communication utilities deployed in Unix OS

CODE:

TELNET

There are times when we are required to connect to a remote Unix machine and work on that

machine remotely. Telnet is a utility that allows a computer user at one site to make a connection,

login and then conduct work on a computer at another site.

Once you login using Telnet, you can perform all the activities on your remotely connected machine.

The finger Utility


The finger command displays information about users on a given host. The host can be either local
or

remote.

Finger may be disabled on other systems for security reasons.

You might also like