Thursday, 24 September 2015

September 24
C Program to display current date

#include <dos.h> #include <stdio.h> int main(void) { struct date d; getdate(&d); printf(“The current year is: %d\n”, d.da_year); printf(“The current day is: %d\n”, d.da_day); printf(“The current month is: %d\n”, d.da_mon); return 0;...
[ Read More ]

September 24
C Program to Set / Change current system date

#include <stdio.h> #include <dos.h> int main(void) { struct time t; gettime(&t); printf(“The current hour is: %d\n”, t.ti_hour); printf(“The current min is: %d\n”, t.ti_min); printf(“The current second is: %d\n”, t.ti_sec); /* Add one to the hour,minute & sec struct element and then call settime */ t.ti_hour++; t.ti_min++; t.ti_sec++; settime(&t); printf(“The current hour is: %d\n”, t.ti_hour); printf(“The current min is: %d\n”, t.ti_min); printf(“The current second is: %d\n”, t.ti_sec); return 0; ...
[ Read More ]
Wednesday, 23 September 2015

September 23
Enter and print details of n employees using structures and dynamic memory allocation

 Enter and print details of n employees using structures and dynamic memory allocation This program is used to show the most basic use of structures. The structure is made of a character array name[], integer age and float salary. We’ll make an array of the structure for the employees. We’ll also use dynamic memory allocation using malloc. You can also use a linked list to the same which is a better option. Let’s check the code. ? #include #include typedef struct{ //structure of emp  char name[30];  int age;  float salary; }emp; int main(){  int n,i;  emp *employee;  printf("Enter no of...
[ Read More ]

September 23
Patterns (one of their favorites)

 Patterns (one of their favorites) If the interviewer asks you a pattern and you don’t know how to do that you are screwed big time. Often you might make a very simple mistake which the interviewer was actually looking for. Here we’ll find out how to print this pattern ? 1 2 3 4 5 A B C D E D C B A   A B C D C B A     A B C B A       A B A         A And here is the code. ? 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 //Printing pattern #include #include int main(){  int...
[ Read More ]
Tuesday, 15 September 2015

September 15
easiest way to sort

#include <stdio.h> #include <stdlib.h> int values[] = { 88, 56, 100, 2, 25 }; int cmpfunc (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int main() { int n; printf("Before sorting the list is: \n"); for( n = 0 ; n < 5; n++ ) { printf("%d ", values[n]); } qsort(values, 5, sizeof(int), cmpfunc); printf("\nAfter sorting the list is: \n"); for( n = 0 ; n < 5; n++ ) { printf("%d ", values[n]); } return(0); }         output   Before sorting the list is: 88 56 100 2 25 After sorting the list is: 2 25 56 88 100...
[ Read More ]
Friday, 11 September 2015

September 11
number of ways a particular no can formed..

#include<stdio.h> // Returns the count of ways we can sum S[0...m-1] coins to get sum nint count( int S[], int m, int n ){    // If n is 0 then there is 1 solution (do not include any coin)    if (n == 0)        return 1;        // If n is less than 0 then no solution exists    if (n < 0)        return 0;    // If there are no coins and n is greater than 0, then no solution exist    if (m <=0 && n >= 1)        return 0;   ...
[ Read More ]
 
 

Labels