C Programming Lab Report.....
C Programming Lab Report.....
BAHAL (BHIWANI)-127028
Lab Manual
PROGRAMMING IN C (B.Sc.(cs) 1st year)
LIST OF PROGRAMS
Program 4: WAP to count number of digits, reverse the digit and sum of digits of a given
number.
Program 11: WAP to swap two numbers using call by value and call by reference.
Program 12: WAP to count number of words, characters and blanks in a string.
Program 13: WAP to illustrate the usage of structure in processing of student record.
#include<stdio.h>
#include<conio.h>
void main()
float fr,cs;
clrscr();
scanf("%f",&fr);
cs=(fr-32)*1.8;
getch();
#include<math.h>
#include<stdio.h>
#include<conio.h>
float s_i(int,int,float);
float c_i(int,int,float);
void main()
int pa,t;
float r,si=0,ci;
clrscr();
printf("\n Enter the principal amount, rate and time: ");
scanf("\n %d%f%d",&pa,&r,&t);
si=pa*r*t/100;
si=s_i(pa,t,r);
ci=c_i(pa,t,r);
ci=ci-pa;
getch();
float temp;
temp=(p*r*t)/100;
return temp;
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();
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;
getch();
/* Program #4: WAP to count number of digits, reverse the digit and sum of digits of a
given number. */
#include<stdio.h>
#include<conio.h>
int n_o_d(int);
int rev_no(int);
int s_o_d(int);
void main ()
int number,nod,sod,rn;
clrscr();
scanf("%d",&number);
nod=n_o_d(number);
sod=s_o_d (number);
rn=rev_no(number);
getch();
int count=0;
while(n!=0)
n=n/10;
count++;
}
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)
while(n!=0)
temp=n%10;
sum=sum+temp;
n=n/10;
return(sum);
#include<conio.h>
int factorial(int);
void main()
int f,n;
clrscr();
scanf("%d",&n);
f=factorial(n);
getch();
if(m==1)
return 1;
return(m*factorial(m-1));
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
int div,n;
clrscr();
scanf("%d",&n);
div=2;
while(div<n/2)
if(n%div==0)
goto end;
//break;
div++;
printf("\n %d is prime",n);
end:
getch();
/* Program #7: WAP to check whether a given year is leap year or not.*/
#include<stdio.h>
#include<conio.h>
void main()
int yr;
clrscr();
if(yr%100==0)
if(yr%400==0)
else
else
if(yr%4==0)
getch();
#include<conio.h>
#include<stdio.h>
void main()
int a[30],no,i,n;
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&no);
for(i=0;i<n;i++)
if(a[i]==no)
goto end;
else
goto end;
end:
getch();
/* Program #9: WAP to find the smallest and largest element in an array. */
#include<stdio.h>
#include<conio.h>
void main()
int a[30],i,min,max,n;
clrscr();
printf("\n Enter the no. of elements in the array:");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
min=a[0];
max=a[0];
for(i=0;i<n;i++)
if(min>a[i])
min=a[i];
if(max<a[i])
max=a[i];
getch();
#include<stdio.h>
#include<conio.h>
void main()
int i,j,m,n,p,q,k;
float a[10][10],b[10][10],c[10][10];
clrscr();
printf("\n Enter the order of first matrix:");
scanf("%d%d",&m,&n);
scanf("%d%d",&p,&q);
if(n!=p)
goto end;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%f",&a[i][j]);
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];
for(i=0;i<m;i++)
for(j=0;j<q;j++)
printf("%f\t",c[i][j]);
printf("\n");
end:
getch();
/* Program #11: WAP to swap two numbers using call by value and call by reference.*/
#include<stdio.h>
#include<conio.h>
void swap(int,int);
void swap_ref(int*,int*);
void main()
int a,b;
clrscr();
scanf("%d%d",&a,&b);
swap_ref(&a,&b);
getch();
int temp;
temp=x;
x=y;
y=temp;
void swap_ref(int*x,int*y)
int temp;
temp=*x;
*x=*y;
*y=temp;
/* Program #12: WAP to count number of words, characters and blanks in a string.*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
char string[100];
int c,noc=0,noblanks=0,i,len=0,nowords=0;
clrscr();
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("\nNo. of words:%d",nowords+1);
getch();
/* Program #13: WAP to illustrate the usage of structure in processing of student record.*/
#include<stdio.h>
#include<conio.h>
void main()
struct student
int roll_no;
char name[30];
float marks;
};
struct student s;
clrscr();
scanf("%s%d%f",&s.name,&s.roll_no,&s.marks);
printf("\n Name:%s",s.name);
printf("\n Marks:%f",s.marks);
getch();
}
/* Program #14: WAP to illustrate encryption/decryption of a string.*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
char string[30];
clrscr();
gets(string);
encryption(string);
getch();
void encryption(char*string)
int i=0;
while(string[i]!='\0')
if(string[i]==' ')
goto jump1;
string[i]=(string[i]-94)%26+97;
else
string[i]=(string[i]-62)%26+65;
jump1:
i++;
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++;
puts(string);
#include<stdio.h>
#include<conio.h>
void main()
int i,*x;
float j,*y;
char k='a',*z;
clrscr();
scanf("%d%f",&i,&j);
x=&i;
y=&j;
z=&k;
x++;
y++;
z++;
x=x-7;
y=y-5;
z=z-2;
getch();