Tuesday, June 26, 2012

Print 1 to 10 Series


#include<stdio.h>
#include<conio.h>
int main()
{
int a;
printf("the no from 1 to 10 are:\n");
for(a=1;a<=10;a++)
printf("%d\n", a);
getch();
}

Tuesday, January 17, 2012

Convert Decimal to Hexadecimal Number


#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
Int x, y=30, z;
clrscr();
printf(“Enter the number:);
scanf(%d”, &x);
printf(“\n conversion of decimal to hexadecimal number\n”);
for(;;)
{
if(x= =0)
exit(1);
z=x%16;
x=x/16;
gotoxy(y--,5);
switch(z)
{
Case 10:
Printf(“A”);
Break;
Case 11:
Printf(%c”, „B?);
Break;
Case 12:
Printf(%c”, „C”);
Break;
Case 13:
Printf(“D”);
Break;
Case 14:
Printf(“E”);
Break;
Case 15:
Printf(“F”);
Default:
Printf(%d”, z);
}
}
getch();
}

Output:
Enter the number: 31
Conversion of decimal to Hexa decimal number
1F

Mark list Analysis using Structures


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
struct stud
{
int rno;
char name[15];
int marks[5];
int total;
float avg;
char class[15];
}
st[10],temp;
int i,n,j;
clrscr();
printf(“\n enter\n”);
scanf(%d”,&n);
for(i=1;i<=n;i++)
{
printf(“\n enter the roll no..);
scanf(%d”,&st[i].rno);
printf(“name...\n”);
scanf(%s”,&st[i].name);
printf(“enter three marks..);
for(j=1;j<=3;j++)
scanf(%d”,&st[i].marks[j]);
}
for(i=1;i<=n;i++)
{
st[i].total=0;
for(j=1;j<=3;j++)
{
st[i].total=st[i].total+st[i].marks[j];
}
st[i].avg=st[i].total/30;
if(st[i].avg>=75)
strcpy(st[i].grade,”distinction”);
elseif(st[i].avg>=60)
strcpy(st[i].grade,”first”);
elseif(st[i].avg>=50)
strcpy(st[i].grade,”second”);
else
strcpy(st[i].grade,”fail”);
}
for(i=1;i<=n;i++)
{
for(j=j+1;j<=n;j++)
{
if(st[i].total<st[j].total)
{
temp=st[i];
st[i]=st[j];
st[j]=temp;
}
}
}
printf(“\n the student details in rankwise\n”);
for(i=1;i<=n;i++)
{ 
printf(“\n\n roll no:%d”,st[i].rno);
printf(“\n name :%s”,st[i].name);
printf(“\n marks in three subjects”);
for(j=1;j<=3;j++)
{
printf(“\n %d,st[i].marks[j]);
}
printf (“\n total: %d”, st[i].total);
printf(“\n average:%f”,st[i].avg);
printf(“\n grade:%s”,st[i].grade);
}
getch();
}

Output:
enter
2
enter the roll no...105
name...sheik raja
enter the three marks...89
87
78
enter roll no...110
name...sriram
enter the three marks...98
96
95

the student details in rankwise

roll no:105
name:sheik raja
marks in three subjects
89
87
78
total:254
average:84.666664
grade:distinction

roll no:110
name:sriram
marks in three subjects
98
96
95
total:289
average:96.3333336
grade:distinction