Search This Blog

Labels

c codes (6) c++ codes (1)

Saturday, February 20, 2016

WAP to take three sides of a triangle as input and print if the triangle is equilateral ,isosceles , scalene.





program code:
#include<stdio.h>
int main()
 {
  int a,b,c;
  printf("Enter a sides of triangle :\n");
  scanf("%d%d%d",&a,&b,&c);
  if((a==b) && (b==c))
   {
    printf( "\nThe triangle formed by %d,%d,%d  sides is equilateral",a,b,c);
   }
  else if((a==b) || (b==c) || (a==c))
   {
     printf( "\nThe triangle formed by %d,%d,%d  sides is isosceles",a,b,c);
   }
 else
    {
      printf( "\nThe triangle formed by %d,%d,%d  sides is scalene",a,b,c);
     }
return 0;
}

Output:-
cse@ubumtu:~$gcc triangle.c - o triangle
cse@ubuntu:~$./triangle
Enter a sides of triangle :
2
4
6
The triangle formed by 2,4,6  sides is scalene.
 Enter a sides of triangle :
2
2
2
The triangle formed by 2,2,2  sides is equilateral
Enter a sides of triangle :
2
2
3
The triangle formed by 2,2,3  sides is isosceles.

Screen shot:-


Saturday, February 06, 2016

c program to print sum of the digits of the given number



c program to print sum of the digits of the given number

 In this program we have to given input a number and we have to find the sum of the digits of the given number and show the result in the output screen. This program is basically used for basic concept who are not known in the c programming.   

program code:-
#include<stdio.h>
int main()
 {
  int n,r,sum,m;
  printf("Enter a number :\n");
  scanf("%d",&n);
  m=n;
  sum=0;
  while(n>0)
    {
      r=n%10;
      sum=sum+r;
      n=n/10;
    }
printf("\n sum of digits of %d is %d ",m,sum);
return 0;
}

Output:-
cse@ubuntu:~$gcc sumdig.c - o sumdig
cse@ubuntu:~$./sumdig
Enter a number : 356

sum of digits of 356 is 14


In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.  

C PROGRAM TO PRINT RADIUS AND VOLUME OF SPHERE



PROGRAM TO PRINT RADIUS AND VOLUME OF SPHERE

Program code:-

#include<stdio.h>
#include<math.h>
#define PI 3.14
int main()
 {
   float radius,sa,vol;
   printf("\nEnter radius of sphere:\n");
   scanf("%f",&radius);
   sa=4*PI*pow(radius,2);
   vol=(sa*PI*radius)/3;
   printf("\nvolume of sphere of %f radius is %f ",radius,vol);
   printf("\nsurface of sphere of %f radius is %f",radius,sa);
return 0;
}

Output:-

tsp@ubuntu:~$gccsphere.c - o sphere
tsp@ubuntu:~$./sphere
Enter radius:
2
volume of sphere of 2.000000 radius is 25.120001

surface area of sphere of 2.000000 radius is 50.240002   



In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.

Tuesday, February 02, 2016

C PROGRAM TO CHECK MATRIX IS UPPER OR LOWER OR TRIDIAGONAL MATRIX

C PROGRAM TO CHECK MATRIX IS UPPER OR LOWER OR TRIDIAGONAL MATRIX

#include<stdio.h>
#define n 4
int main()
{
int a[n][n],i,j,cnt=0,f=0,g=0,k=0,l=0,m=0;
float z=0;
printf("enter the elements of the matrix:-\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]==0)
cnt=cnt+1;
}
}
printf("%d\n",cnt);
z=(cnt*100)/(n*n);
printf("%f\n",z);
if(z>=(n*n)/2)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if((i<j) && a[i][j]!=0)
f=1;
else if((i>j) && a[i][j]!=0)
g=1;
}
}
if(f==1 && g!=1)
printf("lower triangular sparse matrix");
else if(f!=1 && g==1)
printf("upper triangular sparse matrix");
else
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if((i==j) && a[i][j]!=0)
k=1;
if((i+1==j) && a[i][j]!=0)
l=1;
if((i==j+1) && a[i][j]!=0)
m=1;
}
}
if(k==1 && l==1 && m==1)
printf("tridiagnol sparse matrix");
}
}
else printf("not a sparse matrix");
return 0;
}

OUTPUT:-





In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.

Monday, February 01, 2016

C PROGRAM FOR BOTH INSERTION AND DELETION




C PROGRAM FOR BOTH INSERTION AND DELETION

#include<stdio.h>
#define n 10
int main()
{
int a[n],i,b;
printf("A Tarun Sankar\tRoll No. 14115007\n");
printf("Enter elements of array:\n");
for(i=0; i<n; i++)
scanf("%d",&a[i]);
printf("\n\nWhat do you want to do??\n1.Insertion\t2.Deletion:-");
scanf("%d",&i);
if(i==1)
{
int v;
printf("Where do you want to insert the new element?\n");
printf("1.Start\t2.Any position\t3.End:-");
scanf("%d",&i);
printf("Enter the element which you want to insert:-");
scanf("%d",&v);
if(i==1)
{
for(i=0;i>n-1;i++)
a[i+1]=a[i];
a[0]=v;
}
else if(i==2)
{
printf("Enter which postion you want to insert:-");
scanf("%d",&b);
for(i=b;i>n-1; i++)
a[i+1]=a[i];
a[b-1]=v;
}
else if(i==3)
a[n-1]=v;
printf("The array after insertion is:-\n");
for(i=0;i<n; i++)
printf("%d\t",a[i]);
}
else if(i==2)
{
printf("Which element you want to delete?\n1.tart\t2.any position\t3.End:-");
scanf("%d",&i);
if(i==1)
for(i=0;i<n; i++)
a[i]=a[i+1];
else if(i==2)
{
printf("Enter which postion you want to delete:-");
scanf("%d",&b);
for(i=b-1;i<n; i++)
a[i]=a[i+1];
}
printf("The array after deletion is:-\n");
for(i=0; i<n-1; i++)
printf("%d\t",a[i]);
}
return 0;
}
Output:-


In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.

C PROGRAM FOR BOTH BINARY AND LINEAR SEARCH




C PROGRAM FOR BOTH BINARY AND LINEAR SEARCH

#include<stdio.h>
#define n 10
int bRecSear(int arr[], int data, int first, int last);
int main()
{
int a[n],i,v,pos=-1,f=0,l,mid;
printf("Enter the elements of the array:\n");
for(i=0;i<n; i++)
scanf("%d",&a[i]);
printf("How do you want to search??\n1.Linear Search\t2.Binary Search:- ");
scanf("%d",&i);
printf("Enter value to search in array:- ");
scanf("%d",&v);
if(i==1)
{
for(i=0;i<n;i++)
if(a[i]==v)
pos=i;
}
else if(i==2)
{
printf("\nHw do you want to search?\t1.By Itertion\t2.By Recursion:-");
scanf("%d", &i);
if(i==1)
{
l=n-1;
mid =(f+l)/2;
while (f<=l)
{
if (a[mid]<v )
f=mid+1;
else if (a[mid]==v)
{
pos=f;
break;
}
else
l = mid - 1;
mid = (f+l)/2;
}
}
if(i==2)
{
pos=bRecSear(a,v,0,9);
}
}
if(pos==-1)
printf("\nElement not found");
else
printf("\nElement at position:\t%d",pos+1);
return 0;
}
int bRecSear(int arr[], int data, int first, int last)
{
int mid=(first+last)/2, pos=-1;
if(first<=last)
{
if(arr[mid]==data)
{
pos=mid;
}
else if(arr[mid]<data)
{
first=mid+1;
pos=bRecSear(arr, data, first, last);
}
else
{
last=mid-1;
pos=bRecSear(arr, data, first, last);
}
}
return pos;
}

OUTPUT

 


In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.

Pages

Powered By Blogger