Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12-05-2020 Assignment 1 #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
44 changes: 44 additions & 0 deletions Aniruddh 12-05/Q1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdio.h>

#define MAX_SIZE 100

int main()
{
int arr[MAX_SIZE];
int 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;
}
48 changes: 48 additions & 0 deletions Aniruddh 12-05/Q2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20], i, j, k, n;
clrscr();

printf("\nEnter array size: ");
scanf("%d", &n);

printf("\nEnter %d array element: ", n);
for(i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}

printf("\nOriginal array is: ");
for(i = 0; i < n; i++)
{
printf(" %d", a[i]);
}

printf("\nNew array is: ");
for(i = 0; i < n; i++)
{
for(j = i+1; j < n; )
{
if(a[j] == a[i])
{
for(k = j; k < n; k++)
{
a[k] = a[k+1];
}
n--;
}
else
{
j++;
}
}
}

for(i = 0; i < n; i++)
{
printf("%d ", a[i]);
}
getch();
}
26 changes: 26 additions & 0 deletions Aniruddh 12-05/Q3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <math.h>

long decimalToBinary(int decimalnum)
{
long binarynum = 0;
int rem, temp = 1;

while (decimalnum!=0)
{
rem = decimalnum%2;
decimalnum = decimalnum / 2;
binarynum = binarynum + rem*temp;
temp = temp * 10;
}
return binarynum;
}

int main()
{
int decimalnum;
printf("Enter a Decimal Number: ");
scanf("%d", &decimalnum);
printf("Equivalent Binary Number is: %ld", decimalToBinary(decimalnum));
return 0;
}
22 changes: 22 additions & 0 deletions Aniruddh 12-05/Q4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <string.h>
{
int l = 0;
int h = strlen(str) - 1;
while (h > l)
{
if (str[l++] != str[h--])
{
printf("%s is Not Palindrome", str);
return;
}
}
printf("%s is palindrome", str);
}
int main()
{
isPalindrome("abba");
isPalindrome("abbccbba");
isPalindrome("geeks");
return 0;
}
17 changes: 17 additions & 0 deletions Aniruddh 12-05/Q5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
int main()
{
char s1[] = "GeeksforGeeks", s2[100], i;

printf("string s1 : %s\n", s1);

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

s2[i] = '\0';

printf("String s2 : %s", s2);

return 0;
}