The Sum and Average of N Number of Marks of A Student
The Sum and Average of N Number of Marks of A Student
# include<conio.h>
# include<stdio.h>
main()
{
int tam,eng,mat,phy,che,bio,tot;
float avg;
clrscr();
printf("enter the six marks");
scanf("%d%d%d%d%d%d",&tam,&eng,&mat,&phy,&che,&bio);
tot=tam+eng+mat+phy+che+bio;
avg=tot/12;
printf("the total is %d",tot);
printf("the average is %f",avg);
getch();
}
OUTPUT:
Enter the six marks
138
138
85
93
112
111
# include<stdio.h>
# include<conio.h>
main()
{
int fno,sno,tno;
clrscr();
printf("enter any three numbers");
scanf("%d%d%d",&fno,&sno,&tno);
if(fno>sno&&fno>tno)
{
printf("the greatest number is=>%d",fno);
}
else if(sno>tno)
{
printf("the greatest number is=>%d",sno);
}
else
{
printf("the greatest number is=>%d",tno);
}
getch();
}
OUTPUT:
Enter the three numbers
55
76
90
The greatest number is 90
THE GIVEN NUMBER IS PRIME OR NOT AND DISPLAY THE N RANGE OF
PRIME
# include<stdio.h>
# include<conio.h>
main()
{
int n,c=2,i=3,count;
clrscr();
printf("enter a number to check if it is prime\n");
scanf("%d",&n);
for(c=2;c<=n-1;c++)
{
if(n%c==0)
{
printf("%d is not a prime.\n",n);
break;
} }
if(c==n)
printf("%d is a prime.\n",n);
printf("enter the number of prime numbers required\n");
scanf("%d",&n);
if(n>1)
{
printf("first %d prime numbers are:\n",n);
printf("2\n");
}
for(count=2;count<=n;)
{
for(c=2;c<=i-1;c++)
{
if(i%c==0)
break;
}
if(c==i)
{
printf("%d\n",i);
count++;
}
i++;
}
getch();
}
OUTPUT:
# include<stdio.h>
# define MAXSIZE 5
struct stack
{
int stk[MAXSIZE];
int top;
};
typedef struct stack STACK;
STACK s;
void push(void);
int pop(void);
void display(void);
void main()
{
int choice;
int option=1;
s.top=-1;
printf("STACK OPERATION\n");
while(option)
{
printf("-------------------------------\n");
printf(" 1 --> PUSH \n");
printf(" 2 --> POP \n");
printf(" 3 --> DISPLAY \n");
printf(" 4 --> EXIT \n");
printf("-------------------------------\n");
printf("enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
return;
}
fflush (stdin);
printf("do you want to continue(type 0 or 1)?\n");
scanf("%d",&option);
}
}
void push()
{
int num;
if(s.top==(MAXSIZE-1))
{
printf("stack is full\n");
return;
}
else
{
printf("enter the element to be pushed\n");
scanf("%d",&num);
s.top=s.top+1;
s.stk[s.top]=num;
}
return;
}
int pop()
{
int num;
if(s.top==1)
{
printf("stack is empty\n");
return(s.top);
}
else
{
num=s.stk[s.top];
printf("poped element is =%dn",s.stk[s.top]);
s.top=s.top-1;
}
return(num);
}
void display()
{
int i;
if(s.top==-1)
{
printf("stack is empty\n");
return;
}
else
{
printf("\n the status of the stack is\n");
for(i=s.top;i>=0;i--)
{
printf("%d\n",s.stk[i]);
}
}
printf("\n");
}
OUTPUT:
Enter your choice:
5
Do you want to continue (type 0 or 1)
1
The stack is
1
11
111
1111
11111
QUEUE OPERATION
# include<stdio.h>
# define MAX 50
int queue_array[MAX];
int rear=-1;
int front=-1;
main()
{
int choice;
while(1)
{
printf("1.insert element to queue \n");
printf("2.delete element from queue \n");
printf("3.display all element of queue \n");
printf("4.quit\n");
printf("enter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
printf("wrong choice\n");
}
}
}
insert()
{
int add_item;
if(rear==MAX-1)
{
if(front==-1)
front=0;
printf("insert the element in queue:");
scanf("%d",&add_item);
rear=rear+1;
queue_array[rear]=add_item;
}
}
delete()
{
if(front==-1||front>rear)
{
printf("queue underflow\n");
return;
}
else
{
printf("element deleted from queue is:%d\n",queue_array[front]);
front=front+1;
}
}
display()
{
int i;
if(front==-1)
printf("queue is empty\n");
else
{
printf("queue is:\n");
for(i=front;i<=rear;i++)
printf("%d",queue_array[i]);
printf("\n");
}
}
OUTPUT:
Enter the size of queue
2
1. insert
2. delete
3. print
4. exit