Final Project
Final Project
Final Project
Programming
Practical file
Index
s.no
1 2 3 4
Program
Write a Program to return the factorial of a number entered. Write a Program to print the Fibonacci series of number of elements desired. Write a Program that would print the largest number among the entered numbers. Write a Program that would read two matrices and then print another matrix equal to the sum of the two matrices. Write a Program to verify whether the entered number is prime or not. Write a Program to determine whether the entered year is a leap year or not. a)Write a Program to print the following pattern. b). Write a Program to print the following pattern. c). Write a Program to print the following pattern. Write a Program to analyze the number of positive numbers, negative numbers, odd numbers and even numbers in an array of given numbers. Write a Program that would print the area and volume of sphere. Write a Program to sort the elements in an increasing order (bubble sort). Write a Program to count the number of spaces, vowels and words in a string. Write a Program to find the reverse of the given number and the sum of its digit and to check whether a digit exist in that number or not. Write a Program to find the sum of sine and cos. series. Write a Program to print the multiplication table of 5 numbers. Write a Programto find the sum of the series. Write a Program to print smiles on whole screen. Write a Programto swap 2 numbers using function. Write a program that would use different statements to print the value of a declared data type using pointers. Write a program to pass structure to function. Write a program that uses all the file handling commands in C.
Page
1 2 3 4 6 7 8 11 12 13 14 15 16 17 18 19 20 21 22 23
Sign.
5 6 7
9 10 11 12
1 14 15 16 17 18
19 20
OUTPUT:
Q2. Write a Program to print the Fibonacci series of number of elements desired.
#include<stdio.h> #include<conio.h> void main() { inta,b,s=0,i,j; a=0; b=1; clrscr(); printf("Enter the number of elements you want the fibonicci series for:\n"); scanf("%d",&j); printf("The series is\n"); for(i=1;i<=j;i++) { s=a+b; printf("%d\n",s); a=b; b=s; } getch(); }
OUTPUT:
Q3. Write a Program that would print the largest number among the entered numbers.
#include<stdio.h> #include<conio.h> void main() { intlargest,a,b,c; clrscr(); printf("Enter the three numbers:"); scanf("%d%d%d",&a,&b,&c); largest=(a>b&&a>c)?a:((b>c)?b:c); printf("The largest number is=%d",largest); getch(); }
OUTPUT:
Q4. Write a Program that would read two matrices and then print another matrix equal to the sum of the two matrices.
#include<stdio.h> #include<conio.h> void main() { int a[3][3]; int b[3][3]; int c[3][3]; inti,j; clrscr(); printf("Enter the elements in first matrix:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("Enter the elements in second matrix:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&b[i][j]); } } printf("\n"); printf("The first matrix is:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d",a[i][j]); } printf("\n"); } printf("\n"); printf("The second matrix is:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d",b[i][j]); } printf("\n"); } printf("\n"); printf("The resultant matrix:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=(a[i][j]+b[i][j]); printf("%d",c[i][j]);
} printf("\n"); } getch(); }
OUTPUT:
Q5. Write a Program to verify whether the entered number is prime or not.
#include<stdio.h> #include<conio.h> void main() { inti,n,c=0; clrscr(); printf("Enter a number:"); scanf("%d",&n); for(i=1;i<=n;i++) { if(n%i==0) { c++; } } if(c==2) { printf("The number is prime"); } else { printf("The number is not prime"); } getch(); }
OUTPUT:
Q6. Write a Program to determine whether the entered year is a leap year or not.
#include<stdio.h> #include<conio.h> void main() { intyr,i; clrscr(); printf("Enter a year:"); scanf("%d",&yr); if(yr%100==0 && yr%400==0 || yr%100!=0 && yr%4==0) { printf("The year entered is leap"); } else { printf("The year entered is not leap"); } getch(); }
OUTPUT:
Q7. a)Write a Program to print the following pattern. 1 12 123 1234 12345
#include<stdio.h> #include<conio.h> void main() { inti,j; clrscr(); for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("%d",j); } printf("\n"); } getch(); }
OUTPUT:
b). Write a Program to print the following pattern. A AB ABC ABCD ABCDE ABCD ABC AB A
#include<stdio.h> #include<conio.h> void main() { inti,j; for(i=65;i<70;i++) { for(j=65;j<=i;j++) { printf("%c",j); }printf("\n"); } for(i=68;i>=65;i--) { for(j=65;j<=i;j++) { printf("%c",j); } printf("\n"); } getch(); }
OUTPUT:
c). Write a Program to print the following pattern. 1 01 101 0101 10101
#include<stdio.h> #include<conio.h> void main() { inti,j,k; clrscr(); for(i=1;i<=5;i++) { if(i%2==0) { k=0; } else { k=1; } for(j=1;j<=i;j++) { printf("%d",k); k=((k==0)?1:0); } printf("\n"); } getch(); }
OUTPUT:
10
Q8. Write a Program to analyze the number of positive numbers, negative numbers, odd numbers and even numbers in an array of given numbers.
#include<stdio.h> #include<conio.h> void main() { intcount_positive=0,count_negative=0,count_even=0,count_odd=0,i; intar[]={23,5,9,6,17,7,81,49,20,93}; for(i=0;i<10;i++) { if(ar[i]>=0) count_positive++; else count_negative--; if(ar[i]%2==0) count_even++; else count_odd++; } printf(" printf(" printf(" printf(" getch(); } NUMBER NUMBER NUMBER NUMBER OF OF OF OF POSITIVE NUMBERS : %d\n",count_positive); NEGATIVE NUMBERS : %d\n",count_negative); EVEN NUMBERS : %d\n",count_even); ODD NUMBERS : %d\n",count_odd);
OUTPUT:
11
Q9. Write a Program that would print the area and volume of sphere.
#include<stdio.h> #include<conio.h> void main() { floatarea,vol,rad; clrscr(); printf("Enter the radius:"); scanf("%f",&rad); area=(4*3.14*rad*rad*rad); vol=((4/3)*3.14*rad*rad*rad); printf("The area of the sphere is=%f\n",area); printf("The volume of the sphere is=%f",vol); getch(); }
OUTPUT:
12
Q10. Write a Program to sort the elements in an increasing order (bubble sort).
#include<stdio.h> #include<conio.h> void main() { intar[]={2,7,4,8,9,4,1,0,6,4},i,temp,flag; clrscr(); while(1) { flag=0; for(i=0;i<9;i++) { if(ar[i]>ar[i+1]) { temp=ar[i]; ar[i]=ar[i+1]; ar[i+1]=temp; flag=1; } } if(flag==0) break; } for(i=0;i<10;i++) printf("%d\n",ar[i]); getch(); }
OUTPUT:
13
Q11. Write a Program to count the number of spaces, vowels and words in a string.
#include<stdio.h> #include<conio.h> main() { charstr[80]; inti,vowel=0,word=1,space=0; clrscr(); printf("\n enter a string:"); gets(str); for(i=0;str[i]!='\0';i++) { if((str[i]=='a')||(str[i]=='e')||(str[i]=='i')||(str[i]=='o')||(str[i]= ='u')) vowel++; else if(str[i]==' ') { word++; space++; } } printf("\n the number of vowels in the string:%d",vowel); printf("\n the number of words in the string:%d",word); printf("\n the number of white spaces in the string:%d",space); getch(); }
OUTPUT:
14
Q12. Write a Program to find the reverse of the given number and the sum of its digit and to check whether a digit exist in that number or not.
#include<stdio.h> #include<conio.h> void main() { intn,m,rn=0,r,sum=0,digit,flag=1; clrscr(); printf("\n enter the no.:"); scanf("%d",&n); while(n>0) { r=n%10; sum+=r; rn=rn*10+r; n/=10; } printf("\n the no. in reverse order:%d",rn); printf("\n the sum of the digits of the no. %d:%d",n,sum); printf("\n enter the digit to find:"); scanf("%d",&digit); n=m;r=0; while(n>0) { r=n%10; if(r==digit) { flag=1; break; } else flag=0; n/=10; } if(flag==1) printf("\n the digit %d exist in the no.",digit); else printf("\n the digit %d does not exist in the no.",digit); getch(); }
OUTPUT:
15
Q13. Write a Program to find the sum of sine and cos. series.
#include<stdio.h> #include<conio.h> #include<math.h> main() { floatx,sum=0.0,pi=3.14; inti,j,n,fact,t=0; clrscr(); printf("\n enter the angle in degree:"); scanf("%f",&x); x=(pi/180)*x; printf("\n the angle in radian:%f",x); printf("\n enter the value of n:"); scanf("%d",&n); for(i=1;i<=n;i+=2) { fact=1; for(j=i;j>0;j--) fact*=j; sum+=(pow(x,i)/fact)*pow(-1,t); t++; } printf("\n the sum of sine series:%f",sum); getch(); }
OUTPUT:
16
17
OUTPUT:
18
OUTPUT:
19
#include<stdio.h> #include<conio.h> void main() { inta,b; void swap(int *,int *); clrscr(); printf("ENTER TWO NUMBERS\n"); scanf("%d%d",&a,&b); swap(&a,&b); printf("SWAPPED NUMBERS"); printf("\n%d\n%d",a,b); getch(); } void swap(int *ptr1,int *ptr2) { int t; t=*ptr1; *ptr1=*ptr2; *ptr2=t; Getch(); }
OUTPUT:
20
Q18.) Write a program that would use different statements to print the value of a declared data type using pointers. #include<stdio.h> #include<conio.h> #include<string.h> void main(); { int a,*pa; float b,*pb; clrscr(); printf("Enter integer and float value"); scanf("%d %f",&a,&b); pa=&a; pb=&b; printf("Address of a=%u",pa); printf("Value of a=%d",a); printf("Value of a=%d"*(&a)); printf("Value of a=%d"*pa); printf("Address of b=%u",pb); printf("Value of b=%f",b); printf("Value of b=%f",*(&b)); printf("Value of b=%f",*pb); getch(); } OUTPUT:
21
Q19.)Write a program to pass structure to function. #include<stdio.h> #include<conio.h> struct stud { char name[50]; intrno,marks; }s; void main() { strcpy(s.name,"shwetabh"); s.rno=50; s.marks=100; prn(s); } voidprn(struct stud s) { printf("name: %s",s.name); printf("\nrno: %d",s.rno); printf("\nmarks: %d",s.marks); }
OUTPUT:
22
Q20.)Write a program to illustrate all the commands of file handling. #include<stdio.h> #include<conio.h> void main() { FILE *f1,*f2,*f3; intn,i; f1=fopen("Input","w"); /*Create the mother file*/ printf("enter the numbers(2-digit only)"); for(i=1;i<=30;i++) { scanf("%d",&n); if(n>99) break; putw(n,f1); } fclose(f1); f1=fopen("Input","r"); f2=fopen("ODD","w"); f3=fopen("EVEN","w"); while(n=getw(f1)!=EOF) { if(n%2==0) putw(n,f3); /*Write to EVEN file*/ else /*write to ODD file*/ putw(n,f2); } fclose(f1); fclose(f2); fclose(f3); f2=fopen("ODD","r"); printf("ODD file contains\n"); while(n=getw(f2)!=EOF) { printf("%d\n",n); } f3=fopen("EVEN","r"); printf("EVEN file contains\n"); while(n=getw(f3)!=EOF) { printf("%d\n",n); } fclose(f2); fclose(f3); getch(); }
OUTPUT:
23
24