NAME:- Tapajyoti Ghosh
ROLL NUMBER:- GCECTB-R19-2037
STREAM:- I.T( 1st Year 2nd sem)
Programming Assignment_Two on Arrays
Govt. College of Engineering and Ceramic Technology
C Programming for Problem Solving Assignment
First Year Second Semester
Assignment:7 Page Number: 1 Question Number: 1 Full Marks: 100
1. Write a c program which will find whether an element is present in an
array or not using binary search algorithm. Programs must be written
using pointer arithmetic.
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include<time.h>
#pragma comment(lib, "[Link]")
#define MAX_BUFFER 50000
char* Name="Tapajyoti Ghosh";// Change your name here
char* Roll="GCECTB-R19-2037";// Change your roll here
TCHAR* SysInfo_Pranay[]=
{
TEXT("Operating System: %OS%"),
TEXT("User Profile: %USERPROFILE%")
};
void printSystemInfo(void);
int main(void)
{
int *a[100],i,no,*srchno,top,bottom,mid,j,*temp;
printSystemInfo();
printf("\nEnter the number of elements\n");
scanf("%d",&no);
printf("\nEnter %d numbers\n",no);
for(i=0;i<no;++i)
scanf("%d",&a[i]);
printf("Enter the search number\n");
scanf("%d",&srchno);
for(i=0;i<no-1;++i)
for(j=i+1;j<no;++j)
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
printf("\n Sorted array in ascending order\n");
for(i=0;i<no;++i)
printf("%5d",a[i]);
bottom=0;
top=no-1;
while(top!=bottom+1)
{
mid=(bottom+top)/2;
if (a[mid]<=srchno)
bottom=mid;
else
top=mid;
}
if(a[bottom]==srchno)
printf("\n search number is present");
else
printf("\n Search number is not present");
Last Date of Submission:09/04/2020 Signature:
Govt. College of Engineering and Ceramic Technology
C Programming for Problem Solving Assignment
First Year Second Semester
Assignment:7 Page Number: 2 Question Number: 1 Full Marks: 100
return 0;
}
void printSystemInfo(void)
{
TCHAR char_buffer[MAX_BUFFER];
DWORD c=MAX_BUFFER;
c=MAX_BUFFER;
SYSTEM_INFO i;
time_t *t=(time_t *)malloc(sizeof(time_t));
time(t);
struct tm *p=localtime(t);
GetSystemInfo(&i);
GetComputerName(char_buffer,&c);
printf("Name: %s\n",Name);
printf("Roll: %s\n",Roll);
printf("Date: %02d/%02d/%02d\n",p->tm_mday,p->tm_mon+1,p->tm_year+1900);
printf("Time: %02d:%02d:%02d\n",p->tm_hour,p->tm_min,p->tm_sec);
printf("Computer name: %s",char_buffer);
c=MAX_BUFFER;
GetUserName(char_buffer,&c);
printf("\nUser name: %s",char_buffer);
c=ExpandEnvironmentStrings(SysInfo_Pranay[0],char_buffer,MAX_BUFFER);
printf("\n%s",char_buffer);
c=ExpandEnvironmentStrings(SysInfo_Pranay[1],char_buffer,MAX_BUFFER);
printf("\n%s",char_buffer);
printf("\nMachine specific Code: %u\n",[Link]);
printf("Machine specific address: %lx\n",[Link]);
printf("Program Output\n--------------\n");
}
Last Date of Submission:09/04/2020 Signature:
Govt. College of Engineering and Ceramic Technology
C Programming for Problem Solving Assignment
First Year Second Semester
Assignment:7 Page Number: 3 Question Number: 1 Full Marks: 100
OUTPUT:
Last Date of Submission:09/04/2020 Signature:
Govt. College of Engineering and Ceramic Technology
C Programming for Problem Solving Assignment
First Year Second Semester
Assignment:7 Page Number: 4 Question Number: 2 Full Marks: 100
[Link] a C program to search for an element in an array and if
present then also print the frequency and position of the element
in the array.
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include<time.h>
#pragma comment(lib, "[Link]")
#define MAX_BUFFER 50000
char* Name="Tapajyoti Ghosh";// Change your name here
char* Roll="GCECTB-R19-2037";// Change your roll here
TCHAR* SysInfo_Pranay[]=
{
TEXT("Operating System: %OS%"),
TEXT("User Profile: %USERPROFILE%")
};
void printSystemInfo(void);
int main(void)
{
int array[100], search, c, n, count = 0;
printSystemInfo();
printf("Enter number of elements in array: ");
scanf("%d", &n);
printf("Enter %d numbers: \n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
printf("Enter a number to search: ");
scanf("%d", &search);
for (c = 0; c < n; c++) {
if (array[c] == search) {
printf("%d is present at location %d.\n", search, c+1);
count++;
}
}
if (count == 0)
printf("%d isn't present in the array.\n", search);
else
printf("%d is present %d times in the array.\n", search, count);
return 0;
}
void printSystemInfo(void)
{
TCHAR char_buffer[MAX_BUFFER];
DWORD c=MAX_BUFFER;
c=MAX_BUFFER;
SYSTEM_INFO i;
time_t *t=(time_t *)malloc(sizeof(time_t));
time(t);
Last Date of Submission:09/04/2020 Signature:
Govt. College of Engineering and Ceramic Technology
C Programming for Problem Solving Assignment
First Year Second Semester
Assignment:7 Page Number: 5 Question Number: 2 Full Marks: 100
struct tm *p=localtime(t);
GetSystemInfo(&i);
GetComputerName(char_buffer,&c);
printf("Name: %s\n",Name);
printf("Roll: %s\n",Roll);
printf("Date: %02d/%02d/%02d\n",p->tm_mday,p->tm_mon+1,p->tm_year+1900);
printf("Time: %02d:%02d:%02d\n",p->tm_hour,p->tm_min,p->tm_sec);
printf("Computer name: %s",char_buffer);
c=MAX_BUFFER;
GetUserName(char_buffer,&c);
printf("\nUser name: %s",char_buffer);
c=ExpandEnvironmentStrings(SysInfo_Pranay[0],char_buffer,MAX_BUFFER);
printf("\n%s",char_buffer);
c=ExpandEnvironmentStrings(SysInfo_Pranay[1],char_buffer,MAX_BUFFER);
printf("\n%s",char_buffer);
printf("\nMachine specific Code: %u\n",[Link]);
printf("Machine specific address: %lx\n",[Link]);
printf("Program Output\n--------------\n");
}
OUTPUT:
Last Date of Submission:09/04/2020 Signature:
Govt. College of Engineering and Ceramic Technology
C Programming for Problem Solving Assignment
First Year Second Semester
Assignment:7 Page Number: 8 Question Number: 4 Full Marks: 100
[Link] a C program to delete an element from the array and
display the elements of the array after the deletion is performed,
the element to be deleted may be accepted through keyboard as
input. Programs must be written using pointer arithmetic.
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include<time.h>
#pragma comment(lib, "[Link]")
#define MAX_BUFFER 50000
char* Name="Tapajyoti Ghosh";// Change your name here
char* Roll="GCECTB-R19-2037";// Change your roll here
TCHAR* SysInfo_Pranay[]=
{
TEXT("Operating System: %OS%"),
TEXT("User Profile: %USERPROFILE%")
};
void printSystemInfo(void);
int main(void)
{
int i,j,n,arr[100],del,count=0;
printSystemInfo();
printf("Enter the array size:\n");
scanf("%d",&n);
printf("Enter the elements of the array:\n");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("Please enter the element to be deleted:\n");
scanf("%d",&del);
for(i=0;i<n;i++)
{
if(*(arr+i)==del)
{
for(j=i;j<n;j++)
{
*(arr+j)=*(arr+(j+1));
}
count++;
break;
}
}
if(count==0)
{
printf("Element not found..!!");
}
else
{
printf("Element deleted successfully..!!\n");
printf("Now the new array is :\n");
}
Last Date of Submission:11/04/2020 Signature:
Govt. College of Engineering and Ceramic Technology
C Programming for Problem Solving Assignment
First Year Second Semester
Assignment:7 Page Number: 9 Question Number: 4 Full Marks: 100
for(i=0;i<n-1;i++)
{
printf("%d ",*(arr+i));
}
return 0;
}
void printSystemInfo(void)
{
TCHAR char_buffer[MAX_BUFFER];
DWORD c=MAX_BUFFER;
c=MAX_BUFFER;
SYSTEM_INFO i;
time_t *t=(time_t *)malloc(sizeof(time_t));
time(t);
struct tm *p=localtime(t);
GetSystemInfo(&i);
GetComputerName(char_buffer,&c);
printf("Name: %s\n",Name);
printf("Roll: %s\n",Roll);
printf("Date: %02d/%02d/%02d\n",p->tm_mday,p->tm_mon+1,p->tm_year+1900);
printf("Time: %02d:%02d:%02d\n",p->tm_hour,p->tm_min,p->tm_sec);
printf("Computer name: %s",char_buffer);
c=MAX_BUFFER;
GetUserName(char_buffer,&c);
printf("\nUser name: %s",char_buffer);
c=ExpandEnvironmentStrings(SysInfo_Pranay[0],char_buffer,MAX_BUFFER);
printf("\n%s",char_buffer);
c=ExpandEnvironmentStrings(SysInfo_Pranay[1],char_buffer,MAX_BUFFER);
printf("\n%s",char_buffer);
printf("\nMachine specific Code: %u\n",[Link]);
printf("Machine specific address: %lx\n",[Link]);
printf("Program Output\n--------------\n");
}
Last Date of Submission:11/04/2020 Signature:
Govt. College of Engineering and Ceramic Technology
C Programming for Problem Solving Assignment
First Year Second Semester
Assignment:7 Page Number: 11 Question Number: 5 Full Marks: 100
OUTPUT:
Last Date of Submission:09/04/2020 Signature:
Govt. College of Engineering and Ceramic Technology
C Programming for Problem Solving Assignment
First Year Second Semester
Assignment:7 Page Number: 11 Question Number: 5 Full Marks: 100
[Link] a C program to insert an element into the array in a
specified position and display the elements of the array after the
insertion is performed, the element to be inserted may be
accepted through keyboard as input. Programs must be written
using pointer arithmetic.
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include<time.h>
#pragma comment(lib, "[Link]")
#define MAX_BUFFER 50000
char* Name="Tapajyoti Ghosh";// Change your name here
char* Roll="GCECTB-R19-2037";// Change your roll here
TCHAR* SysInfo_Pranay[]=
{
TEXT("Operating System: %OS%"),
TEXT("User Profile: %USERPROFILE%")
};
void printSystemInfo(void);
int main(void)
{
int i,n,arr[100],insert,pos;
printSystemInfo();
printf("Enter Array Size: ");
scanf("%d",&n);
printf("Enter array elements:\n");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("Enter Elements to be inserted: ");
scanf("%d",&insert);
printf("At which position?");
scanf("%d",&pos);
n++;
for(i=n;i>=pos;i--)
{
*(arr+i)=*(arr+(i-1));
}
*(arr+pos-1)=insert;
printf("Element inserted successfully..!!\n");
printf("Now the new array is : \n");
for(i=0;i<n;i++)
{
printf("%d ",*(arr+i));
}
return 0;
}
void printSystemInfo(void)
Last Date of Submission:11/04/2020 Signature:
Govt. College of Engineering and Ceramic Technology
C Programming for Problem Solving Assignment
First Year Second Semester
Assignment:7 Page Number: 12 Question Number: 4 Full Marks: 100
{
TCHAR char_buffer[MAX_BUFFER];
DWORD c=MAX_BUFFER;
c=MAX_BUFFER;
SYSTEM_INFO i;
time_t *t=(time_t *)malloc(sizeof(time_t));
time(t);
struct tm *p=localtime(t);
GetSystemInfo(&i);
GetComputerName(char_buffer,&c);
printf("Name: %s\n",Name);
printf("Roll: %s\n",Roll);
printf("Date: %02d/%02d/%02d\n",p->tm_mday,p->tm_mon+1,p->tm_year+1900);
printf("Time: %02d:%02d:%02d\n",p->tm_hour,p->tm_min,p->tm_sec);
printf("Computer name: %s",char_buffer);
c=MAX_BUFFER;
GetUserName(char_buffer,&c);
printf("\nUser name: %s",char_buffer);
c=ExpandEnvironmentStrings(SysInfo_Pranay[0],char_buffer,MAX_BUFFER);
printf("\n%s",char_buffer);
c=ExpandEnvironmentStrings(SysInfo_Pranay[1],char_buffer,MAX_BUFFER);
printf("\n%s",char_buffer);
printf("\nMachine specific Code: %u\n",[Link]);
printf("Machine specific address: %lx\n",[Link]);
printf("Program Output\n--------------\n");
}
Last Date of Submission:11/04/2020 Signature:
Govt. College of Engineering and Ceramic Technology
C Programming for Problem Solving Assignment
First Year Second Semester
Assignment:7 Page Number: 13 Question Number: 4 Full Marks: 100
OUTPUT:
Last Date of Submission:11/04/2020 Signature: