Posts

Showing posts with the label C

Write a program to print the Year, Month and Date after input the days

#include<stdio.h> #include<conio.h> main() {       int year, remainder, months, days, no_days;              printf("\n\nEnter the number of days : ");       scanf("%d",&no_days);       year=no_days/365;       remainder=no_days%365;       months=remainder/30;       days=remainder%30;       printf("\n\nYour entered days = %d",no_days);       printf("\n\n\nYears = %d \tMonths = %d \tDays = %d",year,months,days);       printf("\n\n\n\n\n\nTHANKING YOU VERY MUCH 'ABHIMANYU KUMAR VATSA'");       getch(); }

Program to insert value in node and print the values

# include <stdio.h> # include <stdlib.h>    struct node    {       int data;       struct node *link;    };    struct node *insert(struct node *p, int n)    {       struct node *temp;       if(p==NULL)       {          p=(struct node *)malloc(sizeof(struct node));          if(p==NULL)          {              printf("Error\n");              exit(0);          }          p-> data = n;          p-> link = NULL;       } else{          p->link = insert(p->link,n);       }       return (p);    }    void printlist ( struct node *p )    {          printf("The data values in the list are\n");          while (p!= NULL)          {             printf("%d\t",p-> data);             p = p-> link;          }    }    void main()    {          int n =10;          int x;          struct node *start = NULL ;          while ( n-- > 0 )          {             s

Binary Search in C Programming

#include<stdio.h> main() {     int low, high, middle, i, item, n, a[20];      //enter the element to be searched     printf("\nEnter the element to search : ");     scanf("%d",&item);      //enter the length of array (<=20)     printf("\nEnter the length of array : ");     scanf("%d",&n);      //enter the array elements     printf("\nEnter the elements for array.\n");     for(i=1;i<=n;i++)         {         scanf("%d",&a[i]);         }     low=1;     high=n;     do     {     middle=(low+high)/2;     if (item<a[middle])         {         high=middle-1;         }     if (item>a[middle])         {         low=middle+1;         }     } while (item!=a[middle] && (low<=high));      //print the result     if (item==a[middle])         printf("%d is found at position %d",item,middle);     else         printf

What is Class?

As we know, in any school system there are many classes and in each classes students belongs to many casts. So, Class is a group of different data types that casts. Class is also works like data type; just its calling terminology is different than all other data types. Integer (int), Character (char), Floating Point (float) is system defined data types but Class is user defined data type. 

Change character string to uppercase

#include <stdio.h> #include <wchar.h>   int main(void) {   wchar_t text[100];     printf("\nEnter the string to be searched(less than 100 characters): ");   fgetws(text, 100, stdin);     /* Convert both strings to uppercase. */   int i;   for(i = 0 ; (text[i] = towupper(text[i])) ; i++);     printf("\nFirst string entered:\n%S\n", text);   getch(); }

Program to print the number in ascending order

#include <iostream> #include <conio.h> void main () { clrscr(); int array [3], t; for (int  x=0; x<3; x++) { cout << "Enter integer number" << x+1 << " : " << endl; cin<< array[x]; } for (x=0; x<3; x++) { for (int y=0; y<2; y++) { if(array[y]>array[y+1]) { t=array[y]; array[y]=array[y+1]; array[y+1]=t; } } } cout << "The integers in ascending order are : "; for (x=0;x<3;x++) cout << endl << array[x]; getch(); } #include <iostream> #include <conio.h> void main () { clrscr(); int array [3], t; for (int  x=0; x<3; x++) { cout << "Enter integer number" << x+1 << " : " << endl; cin<< array[x]; } for (x=0; x<3; x++) { for (int y=0; y<2; y++) { if(array[y]>array[y+1]) { t=array[y]; array[y]=ar

What are differences between sizeof operator and strlen function?

sizeof is keyword of c which can find size of a string constant including null character but strlen is function which has been defined in a header file named string.h and can find number of characters in a string excluding null character. Most probably it is used to compare the size of string with some conditions.   Example:-   #include<string.h> void main(){     int a,b;     a=strlen("itorian");     b=sizeof("itorian");     printf("%d  %d",a,b);     getch(); }

Swap two variables without using third variable in C

There are many ways to do this:-   Solution: 1   void main(){     int x,y;     scanf("%d%d",&x,&y);     //swapping     x=x+y;     y=x-y;     x=x-y;     printf("%d %d",x,y); }   Solution: 2   void main(){     int x,y;     scanf("%d%d",&x,&y);     //swapping     x=x^y;     y=y^x;     x=x^y;     printf("%d %d",x,y); }

Basic File Operations by C and C++

C supports a number of functions that have the ability to perform basic file operations, which include:-   1. Naming a file  2. Opening a file  3. Reading from a file  4. Writing data into a file  5. Closing a file

Program to convert an char array to decimal array

#include<stdio.h> #include<conio.h> void main() { char a1[50]; int a2[50]; printf("enter the characters :"); gets(a1); for(int i=0;a1[i]!='\0';i++) a2[i]=(int)a1[i];     // TYPE CASTING for(i=0;a1[i]!='\0';i++) printf("%d",a2[i]); getch(); }

Write a program for linear search

#include<stdio.h> main() {       int a[100],item,num,i;              printf("\nEnter the number of elements :");       scanf("%d",&num);              printf("\nEnter the array elements :");       for(i=0;i<num;i++)       scanf("%d",&a[i]);              printf("\nEnter the item to search :");       scanf("%d",&item);              for(i=1;i<num;i++)       if(item==a[i])       {         printf("\nItem %d is found at %d position",item,i+1);         end();       }       printf("\nItem not found.");       getch(); }

Creating a student data file using fwrite() function

#include<stdio.h> #include<conio.h> typedef struct { int dd; int mm; int yy; }DATE; typedef struct { char name[20]; int rno; double fees_inst; DATE pay_date; }STDREC; main() {       char wish;       char fees_inst[20];       STDREC std;       FILE *stdfile;       stdfile=fopen("student.dat","wb");       if(stdfile==0)       printf("\nError in opening.\n");       else       do       {           printf("\nEnter name :");           scanf("%s",std.name);           fflush(stdin);           printf("\nEnter roll no :");           scanf("%d",&std.rno);           fflush(stdin);           printf("\nEnter installment amount :");           scanf("%s",fees_inst);           fflush(stdin);           std.fees_inst=atof(fees_inst);           printf("\nEnter pay date mm dd yy :");           scanf("%d/%d/%d&

C Programming Garbage Collection examples

#include<stdio.h> #include<conio.h> main() { printf("%d",printf("CQUESTIONBANK")); getch(); }   OUTPUT: Check the output on your compiler.   So, there are many garbage collection program in C and C++ programming language.   Try out one more program :-   main() { short int a=5; printf("%d"+1,a); getch(); }   OUTPUT: On Terbo 6, 51, d, compiler error etc. and on developer only d will be printed. Try on your compiler.

Program to use realloc() and free() functions

#include<stdio.h> #include<conio.h> main() { char buf[80], *message; printf("\nWhen create pointer it has no address and data also."); printf("\nIn this program please enter at-least one line of text."); printf(" Pfoof given below :\n"); message='\0'; printf("\nMessage is :%s",message); printf("\nAddress is :%p",message); printf("\n\nUsing reallocation function to update message pointer."); printf("\nEnter line of texts :"); gets(buf); message = realloc('\0', strlen(buf)+1);  //here 0 is previous data (NULL) strcpy(message, buf); printf("\nYou message is :%s",message); printf("\nAddress is :%p",message); char *x,*p; x=&message; p=free(x); printf("\nMemory address is :%p",p); getch(); }

Find the ASCII value of a number

# include<stdio.h> # include<conio.h> void main() {   char input;   printf(enter an input to get ascii of input);   scanf(%c,&input);   printf(n ascii of input %c is %d,input,input);   getch(); }

Name five C most popular Compilers

As I know:-   Turbo c/c++ Ansic c Borland c Microsoft c Visual c++ Are the most popular C Compilers.

Without using semicolon print HELLO WORLD on screen

#include<conio.h> main() { if(printf("HELLO WORLD")) { } getch(); }

Program to use putc() and getc() functions

#include<stdio.h>  main() { FILE *f1; char c; printf("Data input output"); f1=fopen("Input","w"); /*Open the file Input*/  while((c=getchar())!=EOF) /*get a character from key board*/  putc(c,f1); /*write a character to input*/  fclose(f1); /*close the file input*/  printf("\nData output\n"); f1=fopen("INPUT","r"); /*Reopen the file input*/  while((c=getc(f1))!=EOF) printf("%c",c); fclose(f1); getch(); }

C Program to abort your program immediately

#include <stdlib.h> #include <stdio.h> main()   {     abort();          //return 0;     getch();   }

Program to find the minimum from array

#include<stdio.h> //creating a function int minimum(values) int values[10]; {     int minimum_value,i;     minimum_value=values[0];     for(i=1;i<10;++i)     {        if(values[i]<minimum_value)        minimum_value=values[i];        return(minimum_value);     } } //main starts here main() {       int scores[10],i,minimum_score;       printf("\nEnter 10 scores.\n");       for(i=0;i<10;++i)       {          scanf("%d",&scores[i]);       }       minimum_score=minimum(scores);       printf("\nMinimum score is %d\n",minimum_score);       getch(); }

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples