GE2115 – Computer Practice Lab - I SEMESTER – I C program Lab manual

Program to find area and circumference of a circle
#include
#include
int main()
{
    float radius, area, circum;
    clrscr();
    printf("Enter radius: ");
    scanf("%f", &radius);
    area   = radius * radius * 22 / 7; /* pr² */
    circum = 2 * radius * 22 / 7;      /* 2pr */
    printf("Area = %f\nCircumference = %f\n", area, circum);
 getch();
     return 0;
}


Factorial of the given number
#include
#include
void main()
{
int fact=1,i,num;
clrscr();
printf("Enter the Number");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
fact=fact*i;

}
printf("The factorial is %d",fact);
getch();
}
Generate the fibonacci series
#include
#include
void main()
{
int x=-1,y=1,z,n,i;
clrscr();
printf("Enter the Series Limit:");
scanf("%d",&n);
for(i=0;i
Roots of Quadratic Equation
#include
#include
#include
void main()
{
int a,b,c,d;
float r1,r2,e;
clrscr();
printf("\n Enter the values of quafratic equation");
scanf("%d%d%d",&a,&b,&c);
d=b*b-4*a*c;
if(d<0)
printf("\n Roots are Imaginary");
else
{
if(d==0)
{
e=-b/2*a;
printf("\n %f",e);
}
else
{
r1=(-b+sqrt(d))/2*a;
r2=(-b-sqrt(d))/2*a;
printf("\n %f,%f are the roots",r1,r2);
}
}
getch();
}
Print the Pascal Triangle
#include
#include

void main()
{
int a[15][15],i,j,rows,num=25,k;
clrscr();
printf("\n enter the number of rows:");
scanf("%d",&rows);
for(i=0;i

Program for Prime or not
#include
#include
void main()
{
int num,i=2;
clrscr();
printf("enter the number:");
scanf("%d",&num);
while(i<=num-1)
{
if(num%i==0)
{
     printf("The number is not a prime number");
     break;
     }
     i++;
     }
     if(i==num)
       printf("the given number is a prime number");
       getch();
   }

Largest of three numbers
#include
#include
void main()
{
int a,b,c;
clrscr();
printf("\n Enter the three numbers:");
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(a>c))
printf("\n %d is greater number",a);
else
{
if(b>c)
printf("\n %d is greater number",b);
else
printf("\n %d is greater number",c);
}
getch();
}

Leap year or not
#include
#include
void main()
{
 int year;
 clrscr();
 printf("enter the year:-  ");
 scanf("%d",&year);
 if(year%4==0)
  printf("%d is a leap year.",year);
 else
  printf("%d is not a leap year.",year);
 getch();
}

Sum of digits
#include
#include
void main()
{
long int num,sum = 0,dig;
clrscr();
printf("\n\n\t ENTER A NUMBER:");
scanf("%ld",&num);
while(num>0)
{
dig = num % 10;
sum = sum + dig;
num = num / 10;
}
printf("\n\t SUM OF DIGITS IS: %ld", sum);
getch();
}

Given number is palindrome or not
#include
#include
void main()
{
unsigned long int a,num,sum=0,rnum=0,rem;
clrscr();
printf("\n Entern the number...");
scanf("%ld",&num);
a=num;
while(num!=0)
{
rem=num%10;
sum=sum+rem;
rnum=rnum*10+rem;
num=num/10;
}
printf("\n The sum of the digits of %ld is %ld \n",a,sum);
printf("\n The reverse number of the %ld is %ld",a,rnum);
if(a==rnum)
printf("\n The given number is a palindrome");
else
printf("\n The given number is not a palindrome");

getch();
}

Given String is palindrome
#include
#include
#include
#define size 26
void main()
{
char strsrc[size];
char strtmp[size];clrscr();
printf("\n Enter String:= ");
 gets(strsrc);strcpy(strtmp,strsrc);
strrev(strtmp);if(strcmp(strsrc,strtmp)==0)
printf("\n Entered string " %s" is palindrome",strsrc);
else
printf("\n Entered string "%s" is not palindrome",strsrc);
getch();

Result analysis of a student
#include
#include
void main()
{
int m1,m2,m3,s,avg;
clrscr();
printf("\t\t RESULT ANALYSIS\n");
printf("Enter the marks in Three Subject:");
scanf("%d%d%d",&m1,&m2,&m3);
s=m1+m2+m3;
avg=s/3;
printf("\n %d is total ",s);
printf("\n %d is Average \n",avg);
if(avg<50)
printf("\n Grade is Fail");
else
{
if((avg>=50)&&(avg<60))
printf("Grade is Second");
else
{
if((avg>=60)&&(avg<75))
printf("Grade is First");
else
printf("Grade is distinction");
}
}
getch();
}

Sum of Square series
#include
#include
void main()
{
int n,i,s=0;
clrscr();
printf("\n Enter the Limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
s=s+i*i;
printf("\n The sum of Square is %d",s);
getch();
}

Given number is armstrong or not
#include
#include
#include
void main()
{
int a,n,b=0,t;
clrscr();
printf("Enter the no");
scanf("%d",&n);
t=n;
while(n>0)
{
a=n%10;
b=b+a*a*a;
n=n/10;
}
if(b==t)
{
printf("Armstrong no");
}
else
{
printf("Not an armstrong no");
}
getch();
}

Menu Driven for a calculator
#include
#include
void main()
{
int a,b,c,ch;
clrscr();
Printf("Arithmetic Operations using Menus\n");
printf("Enter the two values for calculation::");
scanf("%d %d",&a,&b);
printf("\n\t\tMENU\n ");
printf("\n Enter the Choice of Operation \n 1.Add\n2.Sub\n3.Multiply\n4.Division\n5.Remainder\n\n");
scanf("%d",&ch);
switch(ch)
{
case 1:c=a+b;
 break;
case 2:c=a-b;
 break;
case 3:c=a*b;
 break;
case 4:c=a/b;
 break;
case 5:c=a%b;
 break;
default: exit(0);
}
printf("Result=%d",c);
getch();
}

Print the Ascending order of the given array
#include
#include

void main()
{
int a[10],i,n,j,t;
clrscr();
printf("enter size of array: ");
scanf("%d",&n);
printf(" enter array elements: ");
for(i=0;i {
scanf("%d",&a[i]);
}
printf(" array before sorting\n");
for(i=0;i {
printf("%d\n",a[i]);
}
for(i=0;i {
for(j=i+1;j {
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("\n after sorting\n");
for(i=0;i {
printf("%d\n",a[i]);
}
getch();
}

Program for addition of two matrix
void main()
{
int a[3][3],b[3][3],c[3][3],i,j;

printf("Enter the element of first matrix ");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
printf("\n a %d % d :-",i,j);
scanf("%d",&a[i][j]);
}

printf("Enter the element of second matrix ");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
printf("\n b %d % d :-",i,j);
scanf("%d",&b[i][j]);
}
printf("Addition of matrix will be\n ");



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();
}

Find the length and reverse of the string
#include
#include
#include
main()
{
char str1[50];
int len;
printf("Enter the String...");
scanf("%s",str1);
printf("\n The String length of %s is %d",str1,strlen(str1));
printf("\nReverse of the given string is:%s",strrev(str1));
getch();
return 0;
}

Student Report using Structures
#include
#include
#include
struct student
{
char name[20];
int number,m1,m2,m3,total;
float avg;
};

void main()
{
struct student s1;
clrscr();
printf("\n\t\tSTUDENT REPORT USIN STRUCTURES\n");
printf("\n Enter the student name:..");
scanf("%s",&s1.name);
printf("\n Enter the Roll Number of the student:..");
scanf("%d",&s1.number);
printf("\n Enter the Three marks of the student:..");
scanf("%d%d%d",&s1.m1,&s1.m2,&s1.m3);
s1.total=s1.m1+s1.m2+s1.m3;
s1.avg=s1.total/3;
printf("\n Roll Number=%d",s1.number);
printf("\n Name=%s",s1.name);
printf("\n Total=%d \n Average=%f",s1.total,s1.avg);
getch();
}

Program for Sin(X) and Cos(X) Series
Program for Sin(X):
#include
#include
main()
{
float x,t,sum;
int i,n;
printf("Enter the value of x,n: ");
scanf("%f%d",&x,&n);
printf("%4.2f %d\n",x,n);
x=x*3.1412/180;
t=x;
sum=x;
for(i=1;i

Program for Cos(X):
#include
#include
#include
main()
{
int i,n,x;
float t,s;
clrscr();
printf("enter the value of k,n \n");
scanf("%d%d",&x,&n);
t=1;
s=1;
for(i=1;i<=n-1;i++)
{
t=(-1)*((pow(x,2)*t*i))/((2*i)*((2*i-1)*i));
s=s+t;
printf("s=%6.2f & t=%6.2f\n",s,t);
}
printf("\n sum of the cos series=%5.2f\n",s);
getch();
return(0);
}

Program for introducing File primitives
#include

int main()
{
   FILE *f;
   f = fopen("test.txt","w");
   fprintf(f,"Hello");
   fclose(f);
   return 0;
}

Program to convert celsius into fehrenheit
Program to convert celsius into fehrenheit
#include
#include
main()
{
float cel,faren;
clrscr();
printf("Enter the celsius Value...");
scanf("%f",&cel);
faren=(1.8*cel)+32;
printf("The fahrenteiet value of given %f Celsius Value is %f",cel,faren);
getch();
return 0;
}







Previous
Next Post »