Write a C program to delete an element from the array

Posted by Tushar Bedekar

#include< stdio.h>
#include< conio.h>
int main( )
{
int a[20], len, i, n, item, j;
clrscr( );
printf("Enter how many elements you want to enter:");
scanf("%d", &len);

printf("\nEnter the array elements:");
for(i=0; i<'len' ; i++)                                 // remove the single quotes in for loop
scanf("%d", &a[ i]);

printf("\nEnter the location, where you want to delete:");
scanf("%d", &n);

item= a[n-1];
printf("\nDeleted value is : %d", item);

for( j= n-1; j<'len-1; j++) 

{ a[ j]= a[ j+1]; }

len=len-1;
printf("\nThe new element list :");
for(i=0; i<'len; i++)

printf("%5d", a[i]);

getch( );
return 0;
}

Output:-
Enter how many elements you want to enter: 4
Enter the array elements:
10
20
30
40
Enter the location, where you want to delete: 3
Deleted value : 30
The new element list: 10 20 40
Read More

Write a C program to display the message "Welcome to C" without a Semicolon

Posted by Tushar Bedekar

// C program without a Semicolon.
This can done in three ways but one of them is infinite.(ie, while loop)
Solution:1
#include(stdio.h) // note place '<' & '>' in place of '(' & ')'
void main( )
{
if(printf("Welcome to C"))
{
}
}

Solution:2
void main( )
{
switch(printf("Welcome to C"))
{
}
}

Solution:3
void main( )
{
while(printf("Welcome to C")) //infinite loop
{
}
}
Read More

Write a C program that adds first seven terms of the following series 1/1! +2/2! + 3/3! + ..........

Posted by Tushar Bedekar


#include< stdio.h>
#include< conio.h>
int main( )
{
int n,i,j,fact;
float sum=0;
clrscr();
for(i=1; i<=7; i++) { fact=1; for(j=i; j>=1; j--)     // to find the factorial
fact=fact*j;

sum=sum+(float)i/fact;
}
printf("\nSum : %f",sum);
getch();
return 0;
}
Read More

Write a C program to find the greatest common divisor of the two given positive integers

Posted by Tushar Bedekar



#include< stido.h>
#include< conio.h>
int main( )
{
int a, b, res;
clrscr( );
printf("Enter the two integer values:");
scanf("%d%d", &a, &b);

for(  ;  ;  )                                                  //This is empty for loop.
{
res = a%b;
if( res = = 0) break;
a = b;
b = res;
}
printf("\n The GCF is : %d", res);
getch( );
return 0;
}
Read More

HEAP SORTING IN C

Posted by Tushar Bedekar



Q. Write a C program to sort 5 numbers using heap sorting method.


Ans.


/* c program for heap sorting method*/

#include<stdio.h>
#include<conio.h>
void manage(int *, int);
void heapsort(int *, int, int);
int main()
{
 int arr[20]; 
 int i,j,size,tmp,k;
 printf("\n\t------- Heap sorting method -------\n\n");
 printf("Enter the number of elements to sort : ");
 scanf("%d",&size);
 for(i=1; i<=size; i++)
 {
   printf("Enter %d element : ",i);
   scanf("%d",&arr[i]);
   manage(arr,i);
 }
 j=size;
 for(i=1; i<=j; i++)
 {
   tmp=arr[1];
   arr[1]=arr[size];
   arr[size]=tmp;
   size--;
   heapsort(arr,1,size);
 }
 printf("\n\t------- Heap sorted elements -------\n\n");
 size=j;
 for(i=1; i<=size; i++)
     printf("%d ",arr[i]);
 getch();
 return 0;
}


void manage(int *arr, int i)
{
 int tmp; 
 tmp=arr[i];
 while((i>1)&&(arr[i/2]<tmp))
 {
   arr[i]=arr[i/2];
   i=i/2;
 }
 arr[i]=tmp;
}


void heapsort(int *arr, int i, int size)
{
 int tmp,j;
 tmp=arr[i];
 j=i*2;
 while(j<=size)
 {
   if((j<size)&&(arr[j]<arr[j+1]))
      j++;
   if(arr[j]<arr[j/2]) 
      break;
   arr[j/2]=arr[j];
   j=j*2;
 }
 arr[j/2]=tmp;
}

/************* OUTPUT ***************/

Screen shot for Heap sorting C program





Read More

C MAGICAL PROGRAM ME:-

Posted by Tushar Bedekar


void main()
{
int a;
a=300*300/300;
printf(“%d”,a);
}
What will be the output of the above Program

Few options which I can give are -

(1)300
(2)1
(3)81
(4)600
The Correct answer for this question is -

Option 3 i.e. 81

Confused???????

Check here



In C integer has range from -32768 to 32767.
Hence          32767 + 1 = -32768
Similarly       32767 + 3 = -32766

For the above question

300*300=90000

The value stored in integer variable ‘a’ is 24300

Now 24300/300 = 81 



Hence the answer is 81
Read More

Q. Write a C program to print the following V symbol star pyramid as:

Posted by Tushar Bedekar


                                                                        *     *
                                                                         *   *
                                                                          * *
                                                                            *

Soluation:-

/*c pyramid program for v-symbol*/
#include<stdio.h>
int main()
{

 int num=4,r,c,sp;
 for(r=1,c=num+1; r<=num; r++,c=c-2)
 {
   for(sp=r; sp>1; sp--)
      printf(" ");
   printf("*");
   for(sp=c; sp>=1; sp--)
      printf(" ");
   if(c>=1)
      printf("*");
   printf("\n");
 }
 getch();
 return 0;
}

Read More

FREE DOWNLOAD TURBO C-3 FOR WINDOWS XP AND WINDOWS 7

Posted by Tushar Bedekar


Turbo C + + is a C + + compiler with an integrated IDE that was developed by Borland, known because its speed in compilation and linking. This product is part of the family Borland compilers that is very popular  including Turbo Pascal, Turbo Basic, Turbo Prolog and Turbo C. Turbo C + + is a successor of Turbo C which is a further development with uniformity of procedure in the compiler as well as the manner contained in the Turbo Pascal 5.5 adding object functionality in Turbo Pascal versions previously. But unlike the Turbo Pascal, Turbo C + + always follow and maintain the standards that apply to C + + language.





Download links:-



Read More
back to top