Programmer

Thursday 19 April 2018



#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
int a[20][20],i,j,n,count=1;
clrscr();
cout<<"Enter Number :";
cin>>n;
//Loop for storing the values in an array.
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
a[j][i]=count++;
}
}
//Loop for displaying the values of an array.
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
cout.setf(ios::left);
cout<<setw(4)<<a[i][j];
}
cout<<endl;
}
getch();
}

Wednesday 18 April 2018


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>


char nm[][20]={
"Vikas",
"Vishwas",
"Prakash",
"Pradeep",
"Anil",
"Kamal",
"Harshit",
"Jay",
      };
char na[][15]={
"joe",
"austin",
"henry",
"baker",
"chris",
};
struct student
{
int rollno,tot,avg,subm[4],max,min;
char fn[20],fa[15];
};
void sort(student [],int);
void sort(student s[100],int n)
{
int p,i,j,temp;
for(i=0;i<n-1;i++)
{
p=i;
for(j=i+1;j<n;j++)
{
if(s[p].rollno>s[j].rollno)
{
p=j;
}
}
temp=s[i].rollno;
s[i].rollno=s[p].rollno;
s[p].rollno=temp;
}
}
void input(student &s)
{
int x=random(8);
int y=random(5);
strcpy(s.fa,na[y]);
strcpy(s.fn,nm[x]);
s.rollno=random(100);
s.tot=0;
for(int i=0;i<4;i++)
{
s.subm[i]=random(71)+30;
s.tot+=s.subm[i];
}
s.avg=s.tot/4;
s.max=s.min=s.subm[1];
for(int j=0;j<4;j++)
{
if(s.subm[j]>s.max)
{
s.max=s.subm[j];
}
if(s.subm[j]<s.min)
{
s.min=s.subm[j];
}
}
}
void output(student &s)
{
printf("%-9s%-7s%d  ",s.fn,s.fa,s.rollno);
for(int i=0;i<4;i++)
{
if(s.subm[i]>=33)
{
printf("%6d",s.subm[i]);
}
else
{
textcolor(RED+BLINK);
cprintf("%6d",s.subm[i]);
textcolor(7);
}
}
printf("%5d%4d%5d%5d",s.tot,s.avg,s.max,s.min);
int pa=0,f=0;
for(int j=0;j<4;j++)
{
if(s.subm[j]>=33)
{
     pa++;
}
else
{
f++;
}
}
if(f==0 && pa!=0)
{
printf("%6s\n","pass");
}
else
{
printf("%6s\n","Fail");
}
}
void main()
{
student s[100];
int n,i,j,maxE,maxM,maxS,maxG;
clrscr();
printf("Enter the number of students :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
input(s[i]);
}
for(i=0;i<4;i++)
{
if(i==0) //for comparing english subject
{
   maxE=s[0].subm[i];
   for(j=0;j<n;j++)
   {
if(maxE<s[j].subm[i])
maxE=s[j].subm[i];
   }
}
else if(i==1) //For Comparing Maths Subject
{
   maxM=s[0].subm[i];
   for(j=0;j<n;j++)
   {
if(maxM<s[j].subm[i])
maxM=s[j].subm[i];
   }
}
else if(i==2) //For Comparing Science Subject
{
   maxS=s[0].subm[i];
   for(j=0;j<n;j++)
   {
if(maxS<s[j].subm[i])
maxS=s[j].subm[i];
   }
}
else if(i==3) //For Comparing Gujarati Subject
{
   maxG=s[0].subm[i];
   for(j=0;j<n;j++)
   {
if(maxG<s[j].subm[i])
maxG=s[j].subm[i];
   }
}
}

printf("\n-------------------------Students details are as below---------------------\n\n");
printf("     NAME       NO.     Eng  math  sci   guj  TOt  AVg  max min  Rank\n");
sort(s,n);
for(i=0;i<n;i++)
{
output(s[i]);
}
printf("\t\tmax:%6d%6d%6d%6d",maxE,maxM,maxS,maxG);
getch();
}


Saturday 14 April 2018




#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<malloc.h>
struct node
{
int data;
struct node *next;
}*first=NULL,*curr,*prev,*new1;

void insert()
{
int val;
clrscr();
printf("Enter Value :");
scanf("%d",&val);
new1=(struct node*)malloc(sizeof(struct node));
new1->data=val;
new1->next=NULL;

if(first==NULL)
{
first=new1;
return;
}
curr=first;
while(curr->next!=NULL)
{
curr=curr->next;
}
curr->next=new1;
}

void display()
{
if(first==NULL)
printf("Linked list is empty");
curr=first;
while(curr!=NULL)
{
printf("%d-->",curr->data);
curr=curr->next;
}
}

void del()
{
int val;
clrscr();
printf("Which Value U want to Delete ?:");
scanf("%d",&val);

if(first==NULL)
{
printf("Linked list is empty");
}
curr=first;
if(first->data==val)
{
first=first->next;
free(curr);
return;
}

while(curr->data!=val && curr!=NULL)
{
prev=curr;
curr=curr->next;
}
if(curr==NULL)
printf("%d value is not in Linked List",val);

prev->next=curr->next;
free(curr);
}

void after()
{
int val,key;
clrscr();
printf("Enter key :");
scanf("%d",&key);
printf("Enter Value :");
scanf("%d",&val);
new1=(struct node *)malloc(sizeof(struct node));
new1->data=val;
new1->next=NULL;
curr=first;
while(curr->data!=key && curr!=NULL)
{
curr=curr->next;
}
if(curr==NULL)
{
printf("%d key is not in linked list",key);
}
new1->next=curr->next;
curr->next=new1;
}

void before()
{
int val,key;
printf("Enter key :");
scanf("%d",&key);
printf("Enter Val :");
scanf("%d",&val);
new1=(struct node *)malloc(sizeof(struct node));
new1->data=val;
new1->next=NULL;

curr=first;
if(first->data==key)
{
new1->next=first;
first=new1;
return;
}

curr=first;
while(curr->data!=key && curr!=NULL)
{
prev=curr;
curr=curr->next;
}
prev->next=new1;
new1->next=curr;
}

void sort()
{
struct node *i,*j;
int tmp;

if(first==NULL || first->data==NULL)
{
return;
}
i=first;
while(i->next!=NULL)
{
j=i->next;
while(j!=NULL)
{
if(j->data < i->data)
{
tmp=i->data;
i->data=j->data;
j->data=tmp;
}
j=j->next;
}
i=i->next;
}
getch();
}
struct node *rev(struct node *t)
{
struct node *tmp;
if(t->next==NULL)
{
first=t;
return t;
}
tmp=rev(t->next);
tmp->next=t;
return t;
}
void main()
{
int ch;
do
{
clrscr();
printf("***** MENU *****\n");
printf("0. Exit \n");
printf("1. Insert \n");
printf("2. Display \n");
printf("3. Delete \n");
printf("4. Insert After \n");
printf("5. Insert Before\n");
printf("6. Sort \n");
printf("7. Reverse \n");
printf("****************\n");
printf("Enter Your choice :");
scanf("%d",&ch);

switch(ch)
{
case 0: exit(0); break;
case 1: insert(); break;
case 2: display(); break;
case 3: del(); break;
case 4: after(); break;
case 5: before(); break;
case 6: sort(); break;
case 7:
struct node *x;
x=rev(first);
x->next=NULL;
break;
default :
printf("Wrong Input ");
}
getch();
}while(ch>0);
}

Program To Print Particular Line From File.

#include<fstream.h> #include<conio.h> #include<stdlib.h> void main() { ifstream fin; int count=0,num,l=1; char ...