Page 7
61. Program a structure which reads ‘n’ students information (name,3 subjects marks) and calculate total marks, result print them in a particular format.
# include <stdio.h>
# include <conio.h>
main( )
{
struct student
{
char name[20];
int m1,m2,m3, tot;
char result[10];
}stud[10];
int i,n;
clrscr( );
printf(“enter no of students \n”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(”enter %d student deatails \n”,i);
printf(”enter name\n”);
scanf(“%s”, stud[i].name);
printf(“enter marks of 3 subjects \n”);
scanf(“%d%d%d”, &stud[i].m1,&stud[i].m2,&stud[i].m3);
stud[i].tot=stud[i].m1+stud[i].m2+stud[i].m3;
if((stud[i].m1>35)&&(stud[i].m2>35)&&(stud[i].m3>35))
strcpy(stud[i].result,”pass”);
else
strtcpy(stud[i].result,”fail”);
}
clrscr( );
printf(“name total result \n”);
for(i=0;i<n;i++)
{
printf(“%s %d %s \n”, stud[i].name,stud[i].tot,stud[i].result);
}
getch( );
}
62. Program to find whether a square matrix is a) symmetric b) skew symmetric c) none of two.
# include <stdio.h>
# include <conio.h>
main( )
{
int a[10][10],i,j,m,n,c=0,c1=0;
clrscr( );
printf(“enter the array size”);
scanf(“%d”,&n);
printf(“enter the elements”);
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
scanf(“%d”,&a[i][j]);
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
if(a[i][j]==a[j][i])
c=1;
else
if(a[i][j]==a[j][i])
c1=1;
}
printf(“the given matrix is \n”);
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
printf(“%4d”,a[i][j]);
printf(“\n”);
}
if(c==0)
printf(“the given matrix is symmetric”);
else
if(c1==0)
printf(“the matrix is skew symmetric”);
else
printf(“none of two”);
}
getch( );
}
63. Program to find area of a triangle when there sides are given.
# include <stdio.h>
# include <conio.h>
main( )
{
int a,b,c;
float s, area;
clrscr( );
printf(“enter there sides of the triangle”);
scanf(“%d%d%d”,&a,&b,&c);
if((a+b)<c||(b+c)<a||(a+c)<b)
printf(“finding area is not possible”);
else
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf(“area=%.2f”,area);
getch( );
}
64. Program to print Armstrong number between 1-500.
#include<stdio.h>
#include <conio.h>
main( )
{
int i,n,s,r;
clrscr( );
for(i=1;i<=500;i++)
{
n=i;
s=0;
while(n>0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;
}
if(i==s)
printf(“\n%d”,s);
}
getch();
}
65. Program to check whether a given number is Armstrong or not.
# include <stdio.h>
# include <conio.h>
main( )
{
int i,n,s,r,k;
clrscr( );
printf(“enter a number”);
scanf(“%d”,&n);
k=n;
s=0;
while(n>0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;
}
if(k==s)
printf(“given number is Armstrong %d”,k);
else
printf(“given number is not Armstrong %d”,k);
}
getch();
}
66. Program to print the floyd’s triangle.
# include <stdio.h>
# include <conio.h>
main( )
{
int i,n,s,r k=1;
clrscr( );
printf(“enter a number of rows”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
for(s=1;s<=40-i;s++)
printf(“ ”);
for(j=1;j<=i;j++)
printf(“%3d”,k++);
printf(“\n”);
}
getch( );
}
67. Program to read data in 3 structures and print
# include<stdio.h>
# include<conio.h>
main( )
{
struct book
{
char code;
int piece;
float price;
};
struct book b1,b2,b3;
main( )
{
clrscr( );
printf(“enter code,piece,price”);
scanf(“%c%d%f”,&b1.code,&b1.piece,&b1.price);
printf(“enter code,piece,price”);
scanf(“%c%d%f”,&b2.code,&b2.piece,&b2.price);
printf(“enter code,piece,price”);
scanf(“%c%d%f”,&b3.code,&b3.piece,&b3.price);
printf(“the details are”);
printf(“\n %c%d%f”,b1.code,b1.piece,b1.price);
printf(“\n %c%d%f”,b2.code,b2.piece,b2.price);
printf(“\n %c%d%f”,b3.code,b3.piece,b3.price);
getch( );
}
68. Program to print a diagonal matrix.
#include<conio.h>
#include<stdio.h>
main()
{
int a[4][4],i,j;
clrscr( );
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(i==j)
c[i][j]=7;
else
a[i][j]=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf(“%d”,a[i][j]);
printf(“\n”);
}
getch();
}
69. Program to copy contents of one file into another.
#include<stdio.h>
#include<conio.h>
main( )
{
FILE *fp1,*fp2;
char ch;
fp1=fopen(“text1”,”w”);
printf(‘enter the text”);
while((ch=getchar( ))!=EOF)
putc(ch,fp1);
fclose(fp1);
fp1=fopen(“text1”,”r”);
fp2=fopen(“text2”,”w”);
while((ch=getc(fp1))!=EOF)
putc(ch,fp2);
fclose(fp2);
getch( );
}
70. Program to create a file of number and copy odd number into second file and even number into third file.
#include<stdio.h>
#include<conio.h>
main( )
{
FILE *fp1,*fp2,*fp3;
int i;
fp1=fopen(“DATA1”,”w”);
printf(“enter the number”);
scanf(“%d”,&i);
while(i!=eof( ))
{
putw(i,fp1);
}
fcolse(fp1);
fp1=fopen(“DATA1”,”r”);
fp2=fopen(“DATA2”,”w”);
fp3=fopen(“DATA3”,”w”);
while((i=getw(fp1))!=EOF())
if(i%2= =0)
putw(i,fp3);
else
putw(i,fp2);
fcolse(fp1);
fcolse(fp2);
fcolse(fp3);
getch( );
0 comments