Академический Документы
Профессиональный Документы
Культура Документы
Structure :
#include <stdio.h>
struct StudentData
char *student_name;
int student_id;
int student_age;
};
int main()
student.student_id = 20428151;
student.student_age = 20;
return 0;
}
D. Array By Pointer :
#include<stdio.h>
void main()
int data[]={1,2,3,4,5,6,7,8,9,10,11,12,13};
int *p,i,n;
p=&data[0];
n=sizeof(data)/sizeof(data[0]);
for(i=0;i<n;i++)
printf("%d\n", *(p+i));
Description: In this program, we have a pointer p that points to the 0th element of the array. Similarly,
we can also declare a pointer that can point to whole array instead of only one element of the array.
This pointer is useful when talking about multidimensional arrays.
E. Linear Search:
// C code to linearly search x in arr[]. If x
// return -1
#include <stdio.h>
int i;
if (arr[i] == x)
return i;
return -1;
// Driver code
int main(void)
int x = 10;
// Function call
(result == -1)
return 0;
F: Binary Search:
#include <stdio.h>
int main()
scanf("%d", &n);
scanf("%d", &array[c]);
scanf("%d", &search);
first = 0;
last = n - 1;
middle = (first+last)/2;
first = middle + 1;
break;
else
last = middle - 1;
return 0;
G. Bubble Sort:
#include <stdio.h>
int main()
scanf("%d", &n);
scanf("%d", &array[c]);
if (array[d] > array[d+1]) /* For decreasing order use '<' instead of '>' */
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
printf("%d\n", array[c]);
return 0;
H. Infix to postfix:
#include<stdio.h>
#include <ctype.h>
char s[SIZE];
s[++top] = elem;
return (s[top--]);
switch (elem) {
case '#':
return 0;
case '(':
return 1;
case '+':
case '-':
return 2;
case '*':
case '/':
return 3;
int i = 0, k = 0;
scanf("%s", infx);
push('#');
while ((ch = infx[i++]) != '\0') {
if (ch == '(')
push(ch);
else if (isalnum(ch))
pofx[k++] = ch;
pofx[k++] = pop();
} else { /* Operator */
pofx[k++] = pop();
push(ch);
}
while (s[top] != '#') /* Pop from stack till empty */
pofx[k++] = pop();
I. Postfix Evalution:
#include<stdio.h>
#include <ctype.h>
int s[SIZE];
push(int elem)
int pop()
return(s[top--]);
main()
{ /* Main Program */
char pofx[50],ch;
int i=0,op1,op2;
scanf("%s",pofx);
while( (ch=pofx[i++]) != '\0')
else
op2=pop();
op1=pop();
switch(ch)
case '+':push(op1+op2);break;
case '-':push(op1-op2);break;
case '*':push(op1*op2);break;
case '/':push(op1/op2);break;
}
}