Practical Assignment-28
Practical Assignment-28
MCA – DS
Practice Assignment
#include <stdio.h>
return 0;
}
3. Write a C program that accepts the salary and age from the user and displays the
same on the screen as output.]
#include <stdio.h>
int main() {
float salary;
int age;
prin ("Enter your salary: ");
scanf("%f", &salary);
return 0;
}
m=n/2; for(i=2;i<=m;i++)
if(n%i==0)
flag=1;
break;
}
if(flag==0) prin
("Number is prime");
return 0;
b=a-b; a=a-b;
return 0;
{ float P , R
, T , SI ;
P =34000; R =30; T = 5; SI =
{
int num; scanf("%d",&num); if(num
ve");
ve"); return 0;
int n, i;
if (n < 0)
else { for (i = 1; i
*= i;
}
prin ("Factorial of %d = %llu", n, fact);
return 0;
n2 % i == 0)
gcd = i;
prin ("The LCM of two numbers %d and %d is %d.", n1, n2, lcm);
return 0;
%d",n1,n2);//prin ng 0 and 1
for(i=2;i<number;++i
{
n3=n1+n2;
n1=n2;
n2=n3;
return 0;
return 0;
scanf("%d",&n);
temp=n; while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
if(temp==sum) prin
else
0;
scanf("%d",&n);
temp=n; while(n>0)
r=n%10;
sum=sum+(r*r*r);
n=n/10;
if(temp==sum) prin
else
0;
}
15. Write a C Program to Find the Sum of Natural Numbers using
num; prin ("Enter a posi ve integer: "); scanf("%d", &num); prin ("Sum
= %d", addNumbers(num));
return 0;
int addNumbers(int n) {
if (n != 0) return n +
return n;
int main() {
int n;
return 0;
plyNumbers(n-1);
else
return 1;
#include <stdio.h>
#define MAXSIZE 7
#define TRUE
1 #define
FALSE 0
struct Stack {
int top;
int array[MAXSIZE];
} st;
st.top = -1;
} int isFull() {
1) return TRUE;
int isEmpty() {
if(st.top == -1)
return TRUE;
else return
FALSE;
if (isFull()) prin
("Stack is Full...\n");
else { st.array[st.top +
1] = num; st.top++;
}
int pop() { if (isEmpty())
else {
st.top = st.top - 1;
return st.array[st.top+1];
void printStack(){
if(!isEmpty()){ int
temp = pop();
printStack(); prin
push( temp);
if (isEmpty()) {
push(item); } else {
insertAtBo om(item);
push(top);
void reverse() { if
= pop(); reverse();
insertAtBo om(top);
}
}
int getSize(){
return st.top+1;
("Original Stack\n");
printStack(); reverse();
printStack(); return 0;
arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6
}}; for(i=0;i<4;i++){
= %d \n",i,j,arr[i][j]);
}//end of j
}//end of i
return 0;
#include <stdio.h>
#include <conio.h>
int main()
{
int a[1000],i,n,min,max; prin
i<n; i++)
scanf("%d",&a[i]);
}
min=max=a[0];
if(min>a[i])
min=a[i];
if(max<a[i])
max=a[i];
return 0;
20. Write a C Program to Calculate the Average of All the Elements Present in
{2,3,4,54,65,34,23,34,123,80};
for(int i=0;i<10;i++){
sum += arr[i];
= sizeof(arr)/sizeof(arr[0]); prin
prin ("\n");
return 0;
#include<conio.h>
int main()
i<10; i++)
if(a[i]==b[j])
count = 0;
for(x=0; x<k; x++)
if(a[i]==c[x])
count++;
}
if(count==0)
c[k] = a[i];
k++;
getch(); return 0;
23. Write a C Program to Copy All the Elements of One Array to Another
length = sizeof(arr1)/sizeof(arr1[0]);
arr2[i]);
return 0;
#include <stdio.h>
#include <string.h>
int main()
{
char str[] = { "madam" }; int l = 0;
return 0;
#include <stdio.h>
int * getRandom( )
int i;
{ r[i] = rand();
return r;
int main ()
{ int *p;
int i;
p = getRandom();
}
return 0;
isPalindrome(char* string)
'\0') {
++ptr;
--ptr;
if (*ptr == *rev) {
--ptr;
rev++;
} else
break;
Palindrome");
int main()
char str[1000] =
"madam";
isPalindrome(str);
return 0;
int* ptr)
{
int i, j, t;
= i + 1; j < n; j++) {
t = *(ptr + i);
*(ptr + j) = t;
int main()
arr); return 0;
}
28. C Program to Store Informa on of employee using
salary;
};
int main()
&e.id);
scanf("%d", &e.age);
getchar();
scanf("%d", &e.salary);
return 0;
29. C Program to Store employee Records as Structures and Sort them by Name
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
char*
name; int
};
((struct Student*)q)->name);
int main()
int i = 0, n = 5; struct
arr[0].name = "vishal";
arr[0].age = 21;
arr[1].id = 2;
arr[1].name =
"shreeyash";
arr[1].age = 21;
arr[2].id = 3;
arr[2].name = "anant";
arr[2].age = 23;
arr[3].id = 4;
arr[3].name = "harshal";
arr[3].age = 23;
arr[4].id = 5;
arr[4].name = "omkar";
arr[4].age = 23;
arr[i].name, arr[i].age);
arr[i].name, arr[i].age);
return 0;
30. Write a C program to store the names and scores of 5 students in a structure array. Sort
the structure array in descending order of scores. Display the top 3 scores
#include <stdio.h>
#include <string.h>
struct Student {
char name[50];
int score;
};
void sortStudentsByScore(struct Student students[], int n) {
students[j] = temp;
Student students[n];
// Input the names and scores of 5 students
&students[i].score);
sortStudentsByScore(students, n);
return 0;