Search This Blog

Thursday, October 13, 2011

Write a function to find squre and cube of a num

   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  void squrecube(float x,float *s,float *c)
   4:  {
   5:  *s=x*x;
   6:  *c=x*x*x;
   7:  }
   8:  void main()
   9:  {
  10:  float x,s,c;
  11:  printf("enter the num:");
  12:  scanf("%f",&x);
  13:  squrecube(x,&s,&c);
  14:  printf("squre=%f cube=%f",s,c);
  15:  getch();
  16:  }

Write a Program to Give output

1
1 2
1 2 3


   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  void main()
   4:  {
   5:  int i,j,n,s;
   6:  printf("Enter the num of rows:\n");
   7:  scanf("%d",&n);
   8:  for(i=1;i<=n;i++)
   9:      {
  10:      for(s=n-i;s>=1;s--)
  11:          {
  12:          printf(" ");
  13:          }
  14:      for(j=1;j<=i;j++)
  15:          {
  16:          printf("%d ",j);
  17:          }
  18:      printf("\n");
  19:      }
  20:  getch();
  21:  }

Write a program that will provide a character string from command line which translates it into a number and evaluate and display its cube root

   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  #include<math.h>
   4:  #include<stdlib.h>
   5:  void main(int argc,char *argv[])
   6:  {
   7:  float x;
   8:  if(argc<2)
   9:      {
  10:      printf("Insufficient number of arguments supplied:\n");
  11:      getch();
  12:      exit(0);
  13:      }
  14:  x=atof(argv[1]);
  15:  printf("cube root of %f is %f\n",x,pow(x,1.0/3.0));
  16:  getch();
  17:  }

Write a program to read two strings and display them sorted alphabetically

   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  #include<string.h>
   4:  void main()
   5:  {
   6:  char str1[40];
   7:  char str2[40];
   8:  int n;
   9:  printf("Enter the first string:\n");
  10:  gets(str1);
  11:  printf("Enter the second string:\n");
  12:  gets(str2);
  13:  n=strcmp(str1,str2);
  14:      if(n==0)
  15:      {
  16:      printf("the strings are identical\n");
  17:      }
  18:      else
  19:      {
  20:      printf("if sorted alphabetically the strings will come in following order\n");
  21:      }
  22:      if(n<0)
  23:      {
  24:      puts(str1);
  25:      puts(str2);
  26:      }
  27:      if(n>0)
  28:      {
  29:      puts(str2);
  30:      puts(str1);
  31:      }
  32:  getch();
  33:  }

Write a program to read two strings and append second to first

   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  #include<string.h>
   4:  void main()
   5:  {
   6:  char str1[40];
   7:  char str2[40];
   8:  printf("Enter the first string:\n");
   9:  gets(str1);
  10:  printf("Enter the second string:\n");
  11:  gets(str2);
  12:  strcat(str1,str2);
  13:  printf("String 1 is now:\n");
  14:  puts(str1);
  15:  getch();
  16:  }

Write a program that will read names of three students from the keyboard store them as array of strings

   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  #include<string.h>
   4:  void main()
   5:  {
   6:  int i;
   7:  char sname[3][40];
   8:  char yourname[40];
   9:  for(i=0;i<3;i++)
  10:      {
  11:      printf("Enter the name of the student:\n");
  12:      gets(yourname);
  13:      strcpy(sname[i],yourname);
  14:      }
  15:  for(i=0;i<3;i++)
  16:  puts(sname[i]);
  17:  getch();
  18:  }

Write a program to read my number x and to evaluate x*x-2. use a function to evaluate x*x-2 and call this function through its pointer

#include<stdio.h>
#include<conio.h>
#include<math.h>
float expr(float);
void main()
{
float x,value;
printf("Enter the value of x ");
scanf("%f",&x);
value=(*expr)(x);
printf("value =%f\n",value);
getch();
}
float expr(float x)
{
return(x*x-2);
}