Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
5) WAP to copy one string into other string(without using inbuild function strcpy()
ANS
#include <stdio.h>
int main() {
char s1[100], s2[100], i;
printf("Enter string s1: ");
fgets(s1, sizeof(s1), stdin);

for (i = 0; s1[i] != '\0'; ++i) {
s2[i] = s1[i];
}

s2[i] = '\0';
printf("String s2: %s", s2);
return 0;
}

33 changes: 33 additions & 0 deletions assingment#2/questin.1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Q1
#include <stdio.h>
int main()
{
int MAX_SIZE=100, arr[MAX_SIZE], size, i, toSearch, found ;
printf("Enter size of array: ");
scanf("%d", &size);
printf("Enter elements in array: ");
for(i=0; i<size; i++)
{
scanf("%d", &arr[i]);
}
printf("\nEnter element to search: ");
scanf("%d", &toSearch);
found = 0;
for(i=0; i<size; i++)
{if(arr[i] == toSearch)
{
found = 1;
break;
}
}
if(found == 1)
{
printf("\n%d is found at position %d", toSearch, i + 1);
}
else
{
printf("\n%d is not found in the array", toSearch);
}
return 0;
}

35 changes: 35 additions & 0 deletions assingment#2/question .2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Q2
#include <stdio.h>
int main()
{
int MAX_SIZE=100,arr[MAX_SIZE],size,i, j, k;
printf("Enter size of the array : ");
scanf("%d", &size);
printf("Enter elements in array : ");
for(i=0; i<size; i++)
{
scanf("%d", &arr[i]);
}
for(i=0; i<size; i++)
{
for(j=i+1; j<size; j++)
{
if(arr[i] == arr[j])
{
for(k=j; k<size; k++)
{
arr[k] = arr[k + 1];
}
size--;
j--;
}
}
}
printf("\nArray elements after deleting duplicates : ");
for(i=0; i<size; i++)
{
printf("%d\t", arr[i]);
}
return 0;
}

21 changes: 21 additions & 0 deletions assingment#2/question .4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Q4
#include<stdio.h>
int main()
{
char s[1000];
int i,n,c=0;
printf("Enter the string : ");
gets(s);
n=strlen(s);
for(i=0;i<n/2;i++)
{
if(s[i]==s[n-i-1])
c++;
}
if(c==i)
printf("string is palindrome");
else
printf("string is not palindrome");
return 0;
}

20 changes: 20 additions & 0 deletions assingment#2/question .4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Q3
#include<stdio.h>
int main()
{
int a[10],n,i;
printf("Enter the number to convert: ");
scanf("%d",&n);
for(i=0;n>0;i++)
{
a[i]=n%2;
n=n/2;
}
printf("\nBinary of Given Number is=");
for(i=i-1;i>=0;i--)
{
printf("%d",a[i]);
}
return 0;
}