Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Submitted By: Name: Manjeet Course:PGDCA Subject:- Programming using C. Paper Code:- PGDCA-106 Roll No: Semester: 1st
1
INDEX
Sr. No.
1. 2. 3. 4. 5. 6. 7.
Page No. 5 7 9 11 13 15 17 19 22 24 26 29 32 34 36
Remarks
8.
9. 10. 11 12. 13. 14. 15
16. 17.
W.A.P to find factorial of a no. W.A.P to print 1 23 456 7 8 9 10 W.A.P to print * ** *** W.A.P to print the nos. using 1.D array. W.A.P to add 2 matrices W.A.P to multiply 2 matrices. W.A.P to search an element using linear statement. W.A.P to calculate length of a string. W.A.P to copy of a string W.A.P to concatenation of a string. W.A.P to reserve of a string. W.A.P to illustrate the concept of function. W.A.P to illustrate the concept of function prototyping. W.A.P to illustrate the concept of call by reference. W.A.P to illustrate the concept
38 40
18.
42
19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30.
45 47 50 53 57 59 61 63 66 68 70
of call by value. 31. 32 33 W.A.P to calculate factorial of a number using recursion W.A.P to read and write the library data by using structure. W.A.P to find average marks of three subjects of n student by using array of structure. W.A.P to handle bank customer data by using nesting of structure. W.A.Pto show arithmetic operations by using pointer. W.A.P to display the use of pointer. W.A.P to illustrate the concept of array with pointer.
72 74 77 79 82 86 88 90
34.
#include<stdio.h> #include<conio.h> void main() { int a,b,sum=0; clrscr(); printf("Enter the value a,b"); scanf("%d",&a,&b); sum=a+b; printf("sum=%d",sum); getch(); }
OUTPUT
#include<stdio.h> #include<conio.h> void main() { int a,b,c; float avg=0; clrscr(); printf("Enter the value of a,b,c"); scanf("%d%d%d",&a,&b,&c); avg=(a+b+c)/3; printf("Average=%f",avg); getch(); }
OUTPUT
OUTPUT
10
11
OUTPUT
12
13
OUTPUT
14
#include<stdio.h> #include<conio.h> void main() { int a=10, b=20,temp; clrscr(); printf(" Before interchaning the value is a=%d, b=%d",a,b); temp=a; a=b; b=temp; printf("\n After interchaning the value is a=%d,b=%d",a,b); getch(); }
15
OUTPUT
16
#include<stdio.h> #include<conio.h> void main() { int a=10,b=20; clrscr(); printf("Before interchaning the value is a=%d,b=%d",a,b); a=a+b; b=a-b; a=a-b; printf("\n After interchaning the value is a=%d,b=%d",a,b); getch(); }
17
OUTPUT
18
#include<stdio.h> #include<conio.h> void main() { float c,f; clrscr(); printf("Enter the temp in centigrade"); scanf("%f",&c); f=(1.8*c+32); printf("Temp in fahrenhiet is %f",f); getch(); }
19
OUTPUT
20
Control Statements
21
#include<stdio.h> #include<conio.h> void main() { float per; clrscr(); printf("Enter the percentage"); scanf("%f",&per); if(per>80) { printf("Grade is A"); } getch(); }
22
OUTPUT
23
#include<stdio.h> #include<conio.h> void main() { int a; clrscr(); printf("Enter the value of a"); scanf("%d",&a); if(a%2==0) printf("Number is EVEN"); else printf("Number is ODD"); getch(); }
24
OUTPUT
25
#include<stdio.h> #include<conio.h> void main() { int a,b,c; clrscr(); printf("Enter the value of a,b,c"); scanf("%d%d%d",&a,&b,&c); if(a>b); { if(a>c) { printf("Greatest is a"); } else { printf("Greatest is c"); } }
{ if(b>c)
26
27
OUTPUT
28
12. W.A.P to display the color according to code using switch statement.
#include<stdio.h> #include<conio.h> void main() { int code; clrscr(); printf("\n Main Menu"); printf("\n1 For colour Red"); printf("\n2 For colour Green"); printf("\n3 For colour White"); printf("\n4 For colour Yellow"); printf("\n Enter the colour code"); scanf("%d",&code); switch(code) { case 1: printf("\n Colour is Red"); break; case 2: printf("\n Colour is Green"); break; case 3:
29
printf("\n Colour is White"); break; case 4: printf("\n Colour is Yellow"); break; default: printf("\n Colour does not Find"); } getch(); }
30
OUTPUT
31
#include<stdio.h> #include<conio.h> void main() { int i,sum=0,n; float avg; clrscr(); printf("Enter the value of n"); scanf("%d",&n); i=1; while(i<=n) { sum= sum+i; i= i+1; } avg= sum/n; printf("Average=%f",avg); getch(); }
32
OUTPUT
33
#include<stdio.h> #include<conio.h> void main() { int a=0,b=1,c,n,i; clrscr(); printf("Enter the value of n"); scanf("%d",&n); printf("Fibonacci series is"); printf("%d",a); printf("%d",b); for(i=0;i<n-2;i++) { c=a+b; a=b; b=c; printf("%d",c); } getch(); }
34
OUTPUT
35
#include<stdio.h> #include<conio.h> void main() { int sum=0,n,i; float avg; clrscr(); printf("Enter the value of n"); scanf("%d",&n); i=1; do { sum=sum+i; i=i+1; } while(i<n); printf("sum=%d",sum); avg=sum/n; printf("Average=%f",avg); getch(); }
36
OUTPUT
37
#include<stdio.h> #include<conio.h> void main() { int n,i,m; clrscr(); printf("\n Enter the number:"); scanf("%d",&n); m=1; for(i=1;i<=n;i++) { m=m*i; } printf("\n Factorial of %d is = %d",n,m); getch(); }
38
OUTPUT
39
17.W.A.P to print
1 23 456 7 8 9 10
#include<stdio.h> #include<conio.h> void main() { int i,n,j,b=1; clrscr(); printf("\n Enter value of n:"); scanf("%d",&n); for(i=0;i<=n;i++) { for(j=1;j<=i;j++) { printf(" %d",b); b++; } printf("\n"); } getch();
40
OUTPUT
41
42
OUTPUT
43
ARRAYs
44
45
OUTPUT
46
#include<stdio.h> #include<conio.h> void main() { int i,j,a[10][10],b[10][10],c[10][10],n,m; clrscr(); printf("\n Enter the number of rows and columns of matrix A and B:"); scanf("%d%d",&n,&m); printf("\n Enter the elements of matrix A:\n"); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",&a[i][j]); } } printf("\n Enter the elements of matrix B:\n"); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",&b[i][j]);
47
} } for(i=0;i<n;i++) { for(j=0;j<m;j++) { c[i][j]=a[i][j]+b[i][j]; } } printf("\n The resultant matrix c is:\n"); for(i=0;i<n;i++) { for(j=0;j<m;j++) { printf("%d",c[i][j]); printf("\t"); } printf("\n"); } getch(); }
48
OUTPUT
49
{ scanf("%d",&b[i][j]); } for(i=0;i<m;i++) for(j=0;j<q;j++) { c[i][j]=0; for(k=0;k<n;k++) { c[i][j]= c[i][j]+a[i][k]*b[k][j]; } } printf("The resultant martix is\n"); for(i=0;i<m;i++) { for(j=0;j<q;j++) { printf("%d",c[i][j]); printf(" "); } printf("\n"); } getch(); }
51
OUTPUT
52
#include<stdio.h> #include<conio.h> void main() { int a[10],i,item,n,loc,count=0; clrscr(); printf("Enter the no. of element"); scanf("%d",&n); printf("\nEnter the elements one by one"); for(i=0;i<n;i++) scanf("%d",&a[i]); printf("\nEnter the item to be searched"); scanf("%d",&item); for(i=0;i<n;i++) { if(a[i]==item) { loc= i; printf("\n%d is present at loc %d",item,loc+1); count++; } }
53
if(count!=0) printf("\nThe no.is present %d times",count); else printf("Item is not present in the list"); getch(); }
54
OUTPUT
55
String
56
#include<stdio.h> #include<conio.h> void main() { charstr[80]; clrscr(); printf("\n Enter a string"); gets(str); puts(str); printf("\n The length of the string =%d",strlen(str)); getch(); }
57
OUTPUT
58
#include<stdio.h> #include<conio.h> void main() { char source[20], dest[20]; clrscr(); printf("\n Enter a string"); gets(source); strcpy(dest,source); printf("\n The enteressrting is"); puts(source); printf("\n The copied string is"); puts(dest); getch(); }
59
OUTPUT
60
#include<stdio.h> #include<conio.h> void main() { char result[35], blank[]= " "; char s1[]= "Continental", s2[]= "College", s3[]= "Fatehgarh"; clrscr(); strcat(result, s1); strcat(result, blank); strcat(result, s2); strcat(result, blank); strcat(result, s3); strcat(result, blank); printf("\n The resultant string is...\n"); puts(result); getch(); }
61
OUTPUT
62
#include<stdio.h> #include<conio.h> void main() { charstr[20]; clrscr(); printf("\n Enter a string"); gets(str); printf("\n String entered is %s", str); printf("\n String after reserve is %s", strrev(str)); getch(); }
63
OUTPUT
64
Functions
65
#include<stdio.h> #include<conio.h> void main() { int x,y,z,add(); printf("\n Enter the values of x,y:"); scanf("%d%d",&x,&y); x= add(x,y); printf("Added value is %d",x); getche(); } int add(p,q) intp,q; { int s; s= p+q; return(s); }
66
OUTPUT
67
68
OUTPUT
69
70
OUTPUT
71
72
OUTPUT
73
OUTPUT
75
Structures
76
32. W.A.P to read and write the library data by using structure.
#include<stdio.h> #include<conio.h> void main() { struct library { char title[20]; char name[20]; int pages; float price; }book1; printf("Enter the title,name,pages&price of a book"); scanf("%s%s%d%f",book1.title,book1.name,&book1.pages,&book1.price); printf("\n Name of book=%s",book1.title); printf("\n Name of author=%s",book1.name); printf("\n No. of pages=%d",book1.pages); printf("\n Price=%f",book1.price); getch(); }
77
OUTPUT
78
33. W.A.P to find average marks of three subjects of n student by using array of structure.
#include<stdio.h> #include<conio.h> void main() { struct student { int sub1; int sub2; int sub3; }st[10]; int i,n,total; float avg; clrscr(); printf("Enter the no. of student"); scanf("%d",&n); for(i=0;i<n;i++) { printf("\n Enter marks of three sub of %d the student:",i+1); total=0; scanf("%d%d%d",&st[i].sub1,&st[i].sub2,&st[i].sub3); total=st[i].sub1+st[i].sub2+st[i].sub3; avg=(float)total/3;
79
80
OUTPUT
81
{ printf("\n Enter customer name,address and phone-no:"); scanf("\n%s%s%d",cust[i].name,cust[i].address,&cust[i].phone_no); printf("\n Enter the bank branch data:"); for(j=1;j<=m;j++) { printf("\n Enter the branch name, account number :"); scanf("\n %s%d",cust[i].acc[j].b_name,&cust[i].acc[j].account_no); } } printf("\n Customer Date is as:"); for(i=0;i<n;i++) { printf("\n Customer name is =:%s",cust[i].name); printf("\n Customer address is:%s",cust[i].address); printf("\n Customer phone no is:%d",cust[i].phone_no); printf("\n The bank branch data is:"); for(j=1;j<=m;j++) { printf("\n Branch name is:%s",cust[i].acc[j].b_name); printf("\n Account number is:%d",cust[i].acc[j].account_no); } } getch();
83
} .
OUTPUT
84
POINTERS
85
86
OUTPUT
87
88
OUTPUT
89
90
OUTPUT
91