Program to Get Personal Details In C with Cprintf:
#include<stdio.h>
#include<conio.h>
void
main()
{
char
name[10],Add1[15],Add2[15],Phone[11];
clrscr();
textattr(10);
gotoxy(13,3);
cprintf("Name
: ");
cscanf("%s",&name);
fflush(stdin);
gotoxy(10,5);
cprintf("Address
: ");
gets(Add1);
fflush(stdin);
gotoxy(20,6);
gets(Add2);
gotoxy(12,7);
cprintf("Phone
: ");
cscanf("%s",Phone);
gotoxy(15,10);
cprintf("%s %s
%s",name,Add2,Phone);
getch();
}
Output:
Program:Arrange the strings in descending order by their ascii value using Pointers
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,temp,b;
char *anb,a[30];
clrscr();
printf("Enter the string:");
scanf("%s",anb);
printf("\nString:%s",anb);
for(i=0;(*anb)!=NULL;*(++anb))
{
a[i]=*anb;
i++;
}
a[i]=NULL;
printf("\nShow:%s",a);
j=i--;
for(b=0;b<=j;b++)
for(i=0;i<=j;i++)
{
if(a[i]>a[i+1])
a[i]=a[i];
else
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
a[--i]=NULL;
printf("\nOutput:%s",a);
getch();
}
Sample Output:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,temp,b;
char *anb,a[30];
clrscr();
printf("Enter the string:");
scanf("%s",anb);
printf("\nString:%s",anb);
for(i=0;(*anb)!=NULL;*(++anb))
{
a[i]=*anb;
i++;
}
a[i]=NULL;
printf("\nShow:%s",a);
j=i--;
for(b=0;b<=j;b++)
for(i=0;i<=j;i++)
{
if(a[i]>a[i+1])
a[i]=a[i];
else
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
a[--i]=NULL;
printf("\nOutput:%s",a);
getch();
}
Sample Output:
"Anna University Semester Credit Calculator"- Programming using C
Program:
#include<stdio.h>
#include<conio.h>
int mark(int,int);
void main()
{
int four,three,two,five,m4,m3,m2,m1,tot,totm;
float gpa;
clrscr();
printf("\nHow many Sub has 'credit 5': ");
scanf("%d",&five);
printf("\nHow many Sub has 'credit 4': ");
scanf("%d",&four);
printf("\nHow many Sub has 'credit 3': ");
scanf("%d",&three);
printf("\nHow many Lab Subjects: ");
scanf("%d",&two);
tot=(4*four)+(3*three)+(2*two)+(5*five);
m4=mark(4,four);
m3=mark(3,three);
m2=mark(2,two);
m1=mark(5,five);
totm=m4+m3+m2+m1;
gpa=(float)totm/tot;
printf("\n\n *********************** \n");
printf("* *\n");
printf("* Your GPA is: %f *\n",gpa);
printf("* *\n");
printf(" ***********************");
getch();
}
int mark(int grade,int num)
{
int j=1,n,c;
float i=0;
char ma;
c=0;
while(c<num)
{
fflush(0);
clrscr();
label_a:
printf("\nEnter the Grade you scored in the \n");
printf(" 'subject Number-%d' of credit '%d'= ",j,grade);
scanf("%c",&ma);
fflush(0);
switch(ma)
{
case 'S': { n=10; break; }
case 's': { n=10; break; }
case 'A': { n=9; break; }
case 'a': { n=9; break; }
case 'B': { n=8; break; }
case 'b': { n=8; break; }
case 'C': { n=7; break; }
case 'c': { n=7; break; }
case 'D': { n=6; break; }
case 'd': { n=6; break; }
case 'E': { n=5; break; }
case 'e': { n=5; break; }
default: { printf("\nEnter a valid grade\n");
goto label_a;
}
}
i=i+(grade*n);
c++;
j++;
}
return i;
}
Sample Output:
#include<stdio.h>
#include<conio.h>
int mark(int,int);
void main()
{
int four,three,two,five,m4,m3,m2,m1,tot,totm;
float gpa;
clrscr();
printf("\nHow many Sub has 'credit 5': ");
scanf("%d",&five);
printf("\nHow many Sub has 'credit 4': ");
scanf("%d",&four);
printf("\nHow many Sub has 'credit 3': ");
scanf("%d",&three);
printf("\nHow many Lab Subjects: ");
scanf("%d",&two);
tot=(4*four)+(3*three)+(2*two)+(5*five);
m4=mark(4,four);
m3=mark(3,three);
m2=mark(2,two);
m1=mark(5,five);
totm=m4+m3+m2+m1;
gpa=(float)totm/tot;
printf("\n\n *********************** \n");
printf("* *\n");
printf("* Your GPA is: %f *\n",gpa);
printf("* *\n");
printf(" ***********************");
getch();
}
int mark(int grade,int num)
{
int j=1,n,c;
float i=0;
char ma;
c=0;
while(c<num)
{
fflush(0);
clrscr();
label_a:
printf("\nEnter the Grade you scored in the \n");
printf(" 'subject Number-%d' of credit '%d'= ",j,grade);
scanf("%c",&ma);
fflush(0);
switch(ma)
{
case 'S': { n=10; break; }
case 's': { n=10; break; }
case 'A': { n=9; break; }
case 'a': { n=9; break; }
case 'B': { n=8; break; }
case 'b': { n=8; break; }
case 'C': { n=7; break; }
case 'c': { n=7; break; }
case 'D': { n=6; break; }
case 'd': { n=6; break; }
case 'E': { n=5; break; }
case 'e': { n=5; break; }
default: { printf("\nEnter a valid grade\n");
goto label_a;
}
}
i=i+(grade*n);
c++;
j++;
}
return i;
}
Sample Output:
Subscribe to:
Posts (Atom)