NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

no.1 find max number and its location in array
#include <stdio.h>
#include <stdlib.h>

int main() {
int data[10] = {22, 65, 1, 99, 32, 17, 74, 49, 33, 2};
int n = 10;
int loc = 0;
int max = data[0];
int k = 0;

loop:
k = k + 1;
if (k == n) {
printf("Location is %d and the max number is %dn", loc, max);
exit(0);
}
if (max < data[k]) {
loc = k;
max = data[k];
}
goto loop;
}
==================================================
no.2
>>binary search
#include <stdio.h>
int main()
{
int c, first, last, middle, n, search, array[100];

printf("Enter number of elementsn");
scanf("%d", &n);

printf("Enter %d integersn", n);

for (c = 0; c < n; c++)
scanf("%d", &array[c]);

printf("Enter value to findn");
scanf("%d", &search);

first = 0;
last = n - 1;
middle = (first+last)/2;

while (first <= last) {
if (array[middle] < search)
first = middle + 1;
else if (array[middle] == search) {
printf("%d found at location %d.n", search, middle+1);
break;
}
else
last = middle - 1;

middle = (first + last)/2;
}
if (first > last)
printf("Not found! %d isn't present in the list.n", search);

return 0;
}

>>linear search
#include <stdio.h>

int main() {
int array[100] = {23, 56, 21, 33, 56};
int search, c, n = 5;

printf("Given array[] numbersn");
for (c = 0; c < n; c++)
{
printf("%d ", array[c]);
}

printf("nEnter a number to searchn");
scanf("%d", &search);

for (c = 0; c < n; c++)
{
if (array[c] == search)
{
printf("%d is present at location %d.n", search, c + 1);
break;
}
}

if (c == n)
{
printf("%d isn't present in the array.n", search);
}

return 0;
}

>>Quadratic Equation
#include <stdio.h>
#include <math.h>

int main() {
int A, B, C, D;
float X1, X2;

printf("Enter the values of A, B, and C: ");
scanf("%d %d %d", &A, &B, &C);

D = B * B - 4 * A * C;

if (D > 0) {
X1 = (-B + sqrt(D)) / (2.0 * A);
X2 = (-B - sqrt(D)) / (2.0 * A);
printf("X1 = %.2f, X2 = %.2fn", X1, X2);
} else if (D == 0) {
X1 = X2 = -B / (2.0 * A);
printf("UNIQUE SOLUTION X = %.2fn", X1);
} else {
printf("NO REAL SOLUTIONSn");
}

return 0;
}
==================================================
no.3
Code: String Lenght

#include<stdio.h>
#include<string.h>
int main()
{
char string[]="ZubayerAhmed";

int size=strlen(string);

printf("The lenght is: %dn", size);
}

Code: String Copy
#include<stdio.h>
#include<string.h>

int main() {
char x1[] = "Zubayer";
char x2[] = " Ahmed";

strcpy(x1, x2);

printf("The Copied string is: %sn", x1);

return 0;
}

Code: String Concertation
#include<stdio.h>
#include<string.h>

int main()
{
char x1[] = "Zubayer";
char x2[] = " Ahmed";


strcat(x1, x2);

printf("The concatenated string is: %sn", x1);

return 0;
}

Code: String Compare
#include <stdio.h>
#include <string.h>

int main() {
char x1[] = "zubayer", x2[] = "ahmed";
int result;

printf("First String: %sn", x1);
printf("Second String: %sn", x2);

result = strcmp(x1, x2);
printf("Compare between two string= %dn", result);

return 0;
}
==================================================
no.4 1st pattern matching
#include<stdio.h>
#include<string.h>
#include<conio.h>

int main() {
char p[] = "bab";
char t[] = "aabbbabb";
int r, s, k, l, max, index;

r = strlen(p);
s = strlen(t);
k = 0;
max = s - r;

while (k <= max) {
for (l = 0; l < r; l++) {
if (p[l] != t[k + l]) {
break;
}
}
if (l == r) {
index = k;
break;
} else {
k = k + 1;
}
}

if (k > max) {
index = -1;
}

printf("p = %sn", p);
printf("t = %sn", t);

if (index != -1) {
printf("nIndex of p in t is %dn", index);
} else {
printf("n p does not exist in tn");
}

getch();
return 0;
}
==================================================
no.5 stack implementation
#include <stdio.h>

#define MAXSIZE 8
int stack[MAXSIZE];
int top = -1;

int isempty() {
if (top == -1)
return 1;
else
return 0;
}

int isfull() {
if (top == MAXSIZE - 1)
return 1;
else
return 0;
}

int peek() {
return stack[top];
}

int pop() {
int data;
if (!isempty()) {
data = stack[top];
top = top - 1;
return data;
} else {
printf("Could not retrieve data, Stack is empty.n");
}
}

void push(int data) {
if (!isfull()) {
top = top + 1;
stack[top] = data;
} else {
printf("Could not insert data, Stack is full.n");
}
}

int main() {
push(13);
push(21);
push(14);
push(10);
push(12);
push(15);
printf("Element at top of the stack: %dn", peek());
printf("Elements:n");
while (!isempty()) {
int data = pop();
printf("%dn", data);
}
printf("Stack full: %sn", isfull() ? "true" : "false");
printf("Stack empty: %sn", isempty() ? "true" : "false");
return 0;
}
==================================================
no.6 Convert Infix to Postfix using Stack in C
#include <stdio.h>
#include <ctype.h>

char stack[100];
int top = -1;

void push(char x) {
stack[++top] = x;
}

char pop() {
if (top == -1)
return -1;
else
return stack[top--];
}

int priority(char x) {
if (x == '(')
return 0;
if (x == '+' || x == '-')
return 1;
if (x == '*' || x == '/')
return 2;
return 0;
}

int main() {
char exp[100];
char *e, x;
printf("Enter the expression: ");
scanf("%s", exp);
printf("n");
e = exp;
while (*e != '') {
if (isalnum(*e))
printf("%c", *e);
else if (*e == '(')
push(*e);
else if (*e == ')') {
while ((x = pop()) != '(')
printf("%c", x);
} else {
while (priority(stack[top]) >= priority(*e))
printf("%c", pop());
push(*e);
}
e++;
}
while (top != -1)
printf("%c", pop());
return 0;
}
==================================================
no.7 Ackermann Function in C

#include <stdio.h>
int ack(int i, int j)
{
if (i == 0){
return j+1;
}
else if((i > 0) && (j == 0)){
return ack(i-1, 1);
}
else if((i > 0) && (j > 0)){
return ack(i-1, ack(i, j-1));
}
}
int main(){
int Q;
Q = ack(2, 1);
printf("%d", Q);
return 0;
}
==================================================
no.8 Binary Search Tree: In-order, Pre-order, Post-order in C++

#include <iostream>
using namespace std;

struct Node
{
int data;
Node* left;
Node* right;
Node(int n) {
data = n;
left = NULL;
right = NULL;
}
};

void insert(Node* node, int n)
{
if (n < node->data) {
if (node->left == NULL)
node->left = new Node(n);
else
insert(node->left, n);
}
if (n > node->data) {
if (node->right == NULL)
node->right = new Node(n);
else
insert(node->right, n);
}
return;
}

void inorder(Node* root)
{
if (root == NULL)
return;
inorder(root->left);
cout << root->data << " ";
inorder(root->right);
}

void preorder(Node* root)
{
if (root == NULL)
return;
cout << root->data << " ";
preorder(root->left);
preorder(root->right);
}

void postorder(Node* root)
{
if (root == NULL)
return;
postorder(root->left);
postorder(root->right);
cout << root->data << " ";
}

int main() {
int n, x;
Node* root = NULL;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x;
if (root == NULL)
root = new Node(x);
else
insert(root, x);
}
cout << "Inorder: ";
inorder(root);
cout << endl;
cout << "Preorder: ";
preorder(root);
cout << endl;
cout << "Postorder: ";
postorder(root);
cout << endl;
return 0;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.