













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A lab manual for the programming in c course for b.sc.(cs) 1st year students at gdc memorial college, bhiwani. It includes 15 programming problems that cover topics such as temperature conversion, simple and compound interest, finding largest number, counting digits, reversing digits, finding factorials, checking prime numbers, leap year, searching for a given number in an array, finding smallest and largest elements in an array, adding and multiplying matrices, swapping numbers using call by value and call by reference, counting words, characters, and blanks in a string, using structures, encryption/decryption of a string, and pointer arithmetic.
Typology: Cheat Sheet
1 / 21
This page cannot be seen from the preview
Don't miss anything!














printf("\n Enter the principal amount, rate and time: "); scanf("\n %d%f%d",&pa,&r,&t); si=part/100; si=s_i(pa,t,r); printf("\n Simple interest:%f",si); ci=c_i(pa,t,r); ci=ci-pa; printf("\n Compound interest:%f",ci); getch(); } float s_i(int p,int t,float r) { float temp; temp=(prt)/100; return temp; } float c_i(int p,int t,float r) { float temp; temp=p*pow((1+r/100),t); return temp; }
#include<stdio.h>
#include<conio.h> void main() { int a,b,c,largest; clrscr(); printf("\n Enter three numbers:"); scanf("%d%d%d",&a,&b,&c); if(a>b) { if(a>c) largest=a; else largest=c; } else { if(b>c) largest=b; else largest=c; } printf("\n Largest among three numbers is :%d",largest); getch(); }
return(count); } int rev_no(int n) { int rev=0,temp; while(n!=0) { temp=n%10; rev=rev*10+temp; n=n/10; } return(rev); } int s_o_d(int n) { int sum=0, temp; while(n!=0) { temp=n%10; sum=sum+temp; n=n/10; } return(sum); }
#include<stdio.h> #include<conio.h> int factorial(int); void main() { int f,n; clrscr(); printf("\n Enter a number:"); scanf("%d",&n); f=factorial(n); printf("\n Factorial of given no. %d is %d",n,f); getch(); } int factorial (int m) { if(m==1) return 1; return(m*factorial(m-1)); }
#include<stdio.h> #include<conio.h> #include<math.h> void main() { int div,n;
scanf("%d",& yr); if(yr%100==0) { if(yr%400==0) printf("Given year is leap year"); else printf("Given year is not a leap year "); } else { if(yr%4==0) printf("Given year is leap year "); } getch(); }
#include<conio.h> #include<stdio.h> void main() { int a[30],no,i,n; clrscr(); printf("\n Enter the number of elements in the array:"); scanf("%d",&n); printf("\n Enter the array elements"); for(i=0;i<n;i++)
scanf("%d",&a[i]); printf("\n Enter the element to be searched"); scanf("%d",&no); for(i=0;i<n;i++) { if(a[i]==no) { printf("\n Element found at location %d",i+1); goto end; } else { printf("\n Element not found"); goto end; } } end: getch(); }
#include<stdio.h> #include<conio.h> void main() { int a[30],i,min,max,n; clrscr();
printf("\n Enter the order of first matrix:"); scanf("%d%d",&m,&n); printf("\n Enter the order of second matrix:"); scanf("%d%d",&p,&q); if(n!=p) { printf("\n Matrix multiplication is not possible"); goto end; } printf("\n Enter the elements of first matrix: "); for(i=0;i<m;i++) { for(j=0;j<n;j++) scanf("%f",&a[i][j]); } printf("\n Enter the elements of second matrix: "); for(i=0;i<p;i++) { for(j=0;j<q;j++) scanf("%f",&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("\n Resultant matrix is\n "); for(i=0;i<m;i++) { for(j=0;j<q;j++) printf("%f\t",c[i][j]); printf("\n"); } end: getch(); }
#include<stdio.h> #include<conio.h> void swap(int,int); void swap_ref(int,int); void main() { int a,b; clrscr(); printf("\n Enter the numbers:"); scanf("%d%d",&a,&b); printf("\n Swapping of numbers using call by values");
#include<string.h> void main() { char string[100]; int c,noc=0,noblanks=0,i,len=0,nowords=0; clrscr(); printf("\n Enter text :"); gets(string); puts(string); len=strlen(string); for(i=0;i<len;i++) noc++; for(i=0;i<len;i++) { if(string[i]=='\t'||string[i]==' '||string[i]=='\n') noblanks++; } for(i=0;i<len;i++) { if(string[i]==' ') { nowords++; } } noc=noc-noblanks;
printf("\nNo. of characters %d", noc); printf("\n No. of blanks: %d",noblanks); printf("\nNo. of words:%d",nowords+1); getch(); }
#include<stdio.h> #include<conio.h> void main() { struct student { int roll_no; char name[30]; float marks; }; struct student s; clrscr(); printf("\n Enter the name, roll no., marks of student: "); scanf("%s%d%f",&s.name,&s.roll_no,&s.marks); printf("\n The details of student :"); printf("\n Name:%s",s.name); printf("\n Roll No.:%d",s.roll_no); printf("\n Marks:%f",s.marks); getch(); }
jump1: i++; } printf("The encrypted text is:"); puts(String); decryption(string); } void decryption(char*string) { int i=0; while(string[i]!='\0') { if(string[i]==' ') goto jump2; else if((string[i] >= 68 && string[i] <= 90) || \ (string[i] >= 100 && string[i] <= 122)) string[i]-=3; else string[i]+=23; jump2: i++; } printf("The decrypted text is:"); puts(string); }
#include<stdio.h>
#include<conio.h> void main() { int i,x; float j,y; char k='a',*z; clrscr(); printf("\n Enter the values of i, j: "); scanf("%d%f",&i,&j); printf("\n Value of i=%d",i); printf("\n Value of j=%f",j); printf("\n Value of k=%c",k); x=&i; y=&j; z=&k; printf("\n Original address in x=%u",x); printf("\n Original address in y=%u",y); printf("\n Original address in z=%u",z); x++; y++; z++; printf(“\n After incrementing x, y, z:\n”) printf("\n New address in x=%u",x); printf("\n New address in y=%u",y); printf("\n New address in z=%u",z); x=x-7;