1. Student Marklist
2. Sub String
3. Matrix Addition
4. Smallest and Largest in an 2D Array
5. Armstrong number
6. Fibonacci number in array
7. Smallest and Largest in an 1D Array
8. ASCII value
9. Binary Search
10. Array Reverse
1)
C Program for STUDENT MARKLIST.
#include<stdio.h>
#include<conio.h>
int k=0;
struct stud
{
int rn;
char name[30];
int m1,m2,m3,total;
float avg;
char grade,result;
}s[30];
void main()
{
int no,roll=101,i;
clrscr();
printf("Enter NO of Students:");
scanf("%d",&no);
for(i=0;i<no;i++)
{
clrscr();
s[k].rn=roll;
printf("\nEnter the Student Roll Number: %d ",s[k].rn);
printf("\nEnter the Student Name:");
fflush(stdin);
gets(s[k].name);
printf("\nEnter the Three Marks");
scanf("%d",&s[k].m1);
scanf("%d",&s[k].m2);
scanf("%d",&s[k].m3);
if(s[k].m1>=35 && s[k].m2>=35 && s[k].m3>=35)
{
s[k].result='P';
}
else
{
s[k].result = 'F';
}
s[k].total = s[k].m1+s[k].m2+s[k].m3;
printf("The Total is : %d",s[k].total);
s[k].avg=s[k].total/3;
if(s[k].avg>=60)
{
if(s[k].result == 'P')
{
s[k].grade = 'A';
}
else
{
s[k].grade = 'N';
}
}
else if(s[k].avg>=50)
{
if(s[k].result == 'P')
{
s[k].grade = 'B';
}
else
{
s[k].grade = 'N';
}
}
else if(s[k].avg>=35)
{
if(s[k].result == 'P')
{
s[k].grade = 'C';
}
else
{
s[k].grade = 'N';
}
}
getch();
k++;
roll++;
}
printf("\n*******************************************************");
printf("\n STUDENT MARKLIST ");
printf("\n*******************************************************");
printf("\nROLL \tNAME MARK1 MARK2 MARK3 TOTAL RESULT Average GRADE");
for(i=0;i<no;i++)
{
printf("\n%d\t%s %d %d %d %d %c %0.1f %c",s[i].rn,s[i].name,s[i].m1,s[i].m2,s[i].m3,s[i].total,s[i].result,s[i].avg,s[i].grade);
}
getch();
}
#include<stdio.h>
#include<conio.h>
int k=0;
struct stud
{
int rn;
char name[30];
int m1,m2,m3,total;
float avg;
char grade,result;
}s[30];
void main()
{
int no,roll=101,i;
clrscr();
printf("Enter NO of Students:");
scanf("%d",&no);
for(i=0;i<no;i++)
{
clrscr();
s[k].rn=roll;
printf("\nEnter the Student Roll Number: %d ",s[k].rn);
printf("\nEnter the Student Name:");
fflush(stdin);
gets(s[k].name);
printf("\nEnter the Three Marks");
scanf("%d",&s[k].m1);
scanf("%d",&s[k].m2);
scanf("%d",&s[k].m3);
if(s[k].m1>=35 && s[k].m2>=35 && s[k].m3>=35)
{
s[k].result='P';
}
else
{
s[k].result = 'F';
}
s[k].total = s[k].m1+s[k].m2+s[k].m3;
printf("The Total is : %d",s[k].total);
s[k].avg=s[k].total/3;
if(s[k].avg>=60)
{
if(s[k].result == 'P')
{
s[k].grade = 'A';
}
else
{
s[k].grade = 'N';
}
}
else if(s[k].avg>=50)
{
if(s[k].result == 'P')
{
s[k].grade = 'B';
}
else
{
s[k].grade = 'N';
}
}
else if(s[k].avg>=35)
{
if(s[k].result == 'P')
{
s[k].grade = 'C';
}
else
{
s[k].grade = 'N';
}
}
getch();
k++;
roll++;
}
printf("\n*******************************************************");
printf("\n STUDENT MARKLIST ");
printf("\n*******************************************************");
printf("\nROLL \tNAME MARK1 MARK2 MARK3 TOTAL RESULT Average GRADE");
for(i=0;i<no;i++)
{
printf("\n%d\t%s %d %d %d %d %c %0.1f %c",s[i].rn,s[i].name,s[i].m1,s[i].m2,s[i].m3,s[i].total,s[i].result,s[i].avg,s[i].grade);
}
getch();
}
2)
C Program for SubString.
#include<stdio.h>
#include<conio.h>
void main()
{
char a[30],b[30];
int i,j,l1,l2,c,f;
clrscr();
printf("OUTPUT\n");
printf("------\n");
printf("\n\n");
printf("\nEnter First String:");
scanf("%s",a);
printf("\nEnter String to Search:");
scanf("%s",b);
l1=strlen(a);
l2=strlen(b);
j=0;
c=0;
f=0;
for(i=0;i<l1;i++)
{
x:
if(b[j]==a[i])
{
c++;
f=1;
j++;
if(c==l2)goto y;
}
else
{
if(f==1)
{
j=0;
c=0;
f=0;
goto x;
}
}
}
y:
if(c==l2)
printf("\n\t\tWord Found");
else
printf("\n\t\tWord Not Found");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
char a[30],b[30];
int i,j,l1,l2,c,f;
clrscr();
printf("OUTPUT\n");
printf("------\n");
printf("\n\n");
printf("\nEnter First String:");
scanf("%s",a);
printf("\nEnter String to Search:");
scanf("%s",b);
l1=strlen(a);
l2=strlen(b);
j=0;
c=0;
f=0;
for(i=0;i<l1;i++)
{
x:
if(b[j]==a[i])
{
c++;
f=1;
j++;
if(c==l2)goto y;
}
else
{
if(f==1)
{
j=0;
c=0;
f=0;
goto x;
}
}
}
y:
if(c==l2)
printf("\n\t\tWord Found");
else
printf("\n\t\tWord Not Found");
getch();
}
3)
C Program For to find largest and smallest value in two dimension matrix.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,r,c,a[10][10],largest=0,smallest,z=1,t;
clrscr();
printf("Enter the r and c value:");
scanf("%d%d",&r,&c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
largest=0;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
if(largest<a[i][j])
{
largest=a[i][j];
}
}
}
t=a[1][1];
a[1][1]=smallest;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
if(smallest>a[i][j])
{
smallest=a[i][j];
}
else
{
z++;
}
if(z==(r*c))
{
smallest=t;
}
}
}
printf("largest elemement=%d\n",largest);
printf("smallest element=%d\n",smallest);
getch();
}</a[i][j])
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,r,c,a[10][10],largest=0,smallest,z=1,t;
clrscr();
printf("Enter the r and c value:");
scanf("%d%d",&r,&c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
largest=0;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
if(largest<a[i][j])
{
largest=a[i][j];
}
}
}
t=a[1][1];
a[1][1]=smallest;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
if(smallest>a[i][j])
{
smallest=a[i][j];
}
else
{
z++;
}
if(z==(r*c))
{
smallest=t;
}
}
}
printf("largest elemement=%d\n",largest);
printf("smallest element=%d\n",smallest);
getch();
}</a[i][j])
4)
C Program For Matrix addition.
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,a[10][10],i,j,m,n,b[10][10],z[10][10];
clrscr();
printf("Enter r and c value:");
scanf("%d%d",&r,&c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
for(m=1;m<=r;m++)
{
for(n=1;n<=c;n++)
{
printf("b[%d][%d]=",m,n);
scanf("%d",&b[m][n]);
}
}
// z[i][j]=0;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
z[i][j]=(a[i][j]+b[i][j]);
}
}
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("%d\t",z[i][j]);
}
printf("\n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,a[10][10],i,j,m,n,b[10][10],z[10][10];
clrscr();
printf("Enter r and c value:");
scanf("%d%d",&r,&c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
for(m=1;m<=r;m++)
{
for(n=1;n<=c;n++)
{
printf("b[%d][%d]=",m,n);
scanf("%d",&b[m][n]);
}
}
// z[i][j]=0;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
z[i][j]=(a[i][j]+b[i][j]);
}
}
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("%d\t",z[i][j]);
}
printf("\n");
}
getch();
}
5)
C Program For ARMSTRONG NUMBER.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,t,s=0,k;
clrscr();
printf("Enter the n value:");
scanf("%d",&k);
n=k;
while(n>0)
{
t=n%10;
s=s+t*t*t;
n=n/10;
}
if(k==s)
{
printf("given %d is armstrong number",k);
}
else
{
printf("not armstrong number");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,t,s=0,k;
clrscr();
printf("Enter the n value:");
scanf("%d",&k);
n=k;
while(n>0)
{
t=n%10;
s=s+t*t*t;
n=n/10;
}
if(k==s)
{
printf("given %d is armstrong number",k);
}
else
{
printf("not armstrong number");
}
getch();
}
6)
C Program For FINDING ONE DIMENSIONAL ARRAY BIG AND SMALL ELEMENT.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a[10],max,min;
clrscr();
printf("Enter the n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the a[%d]=",i);
scanf("%d",&a[i]);
}
max=0;
for(i=1;i<=n;i++)
{
if(a[i]>max)
{
max=a[i];
}
if(a[i]<min)
{
min=a[i];
}
}
printf("maximum is =%d",max);
printf("minimum is=%d",min);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a[10],max,min;
clrscr();
printf("Enter the n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the a[%d]=",i);
scanf("%d",&a[i]);
}
max=0;
for(i=1;i<=n;i++)
{
if(a[i]>max)
{
max=a[i];
}
if(a[i]<min)
{
min=a[i];
}
}
printf("maximum is =%d",max);
printf("minimum is=%d",min);
getch();
}
7)
C Program For FIBINACCI SERIES USING ARRAY.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a[20];
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
a[0]=0;
a[1]=1;
printf("%d\n",a[0]);
printf("%d\n",a[1]);
for(i=2;i<n;i++)
{
a[i]=a[i-1]+a[i-2];
printf("%d\n",a[i]);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a[20];
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
a[0]=0;
a[1]=1;
printf("%d\n",a[0]);
printf("%d\n",a[1]);
for(i=2;i<n;i++)
{
a[i]=a[i-1]+a[i-2];
printf("%d\n",a[i]);
}
getch();
}
8)
C Program For ARRAY REVERSE.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],i,n;
clrscr();
printf("Enter the n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("enter the a[%d]=",i);
scanf("%d",&a[i]);
}
for(i=n;i>0;i--)
{
printf("%d\n",a[i]);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],i,n;
clrscr();
printf("Enter the n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("enter the a[%d]=",i);
scanf("%d",&a[i]);
}
for(i=n;i>0;i--)
{
printf("%d\n",a[i]);
}
getch();
}
9)
C Program For ASCII VALUE.
#include<stdio.h>
#include<conio.h>
void main()
{
int t,k,n;
clrscr();
printf("Enter the password");
scanf("%d",&n);
while(n>0)
{
t=n%10;
t=t+1;
printf("%c\n",t);
//printf("%d\n",t);
n=n/10;
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int t,k,n;
clrscr();
printf("Enter the password");
scanf("%d",&n);
while(n>0)
{
t=n%10;
t=t+1;
printf("%c\n",t);
//printf("%d\n",t);
n=n/10;
}
getch();
}
10)
C Program For BINARY SEARCH.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,search,f=0,low,high,mid,a[20];
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the number in ascending order a[%d]=",i);
scanf("%d",&a[i]);
}
printf("Enter the search element:");
scanf("%d",&search);
low=1;
high=n;
while(low<=high)
{
mid=(low+high)/2;
if(search<a[mid])
{
high=mid-1;
}
else if(search>a[mid])
{
low=mid+1;
}
else
{
f=1;
printf("obtainedin the position %d:",mid);
getch();
exit();
}
}
if(f==0)
{
printf("not present");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,search,f=0,low,high,mid,a[20];
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the number in ascending order a[%d]=",i);
scanf("%d",&a[i]);
}
printf("Enter the search element:");
scanf("%d",&search);
low=1;
high=n;
while(low<=high)
{
mid=(low+high)/2;
if(search<a[mid])
{
high=mid-1;
}
else if(search>a[mid])
{
low=mid+1;
}
else
{
f=1;
printf("obtainedin the position %d:",mid);
getch();
exit();
}
}
if(f==0)
{
printf("not present");
}
getch();
}
0 comments:
Post a Comment