Posts

Print pattern in c - number pattern -2

Print pattern in c - number pattern -2 Write a program to print following pattern 12345 2345 345 45 5 Program code #include <stdio.h> int main() {     int i, j;     for(i=1;i<=5;i++)     {         for(j=i;j<=5;j++)         {             printf("%d",j);         }         printf("\n");     }     return 0; } Step by Step solution 1. Number of row -    Is has 5row  , so first loop will execute for 5 time #include <stdio.h> int main() {     int i, j;     for(i=1;i>=5;i++)     {...... }     return 0; } 2. Number of character -  It has only one type of character , so there will be only one nested loop #include <stdio.h> int main() { ...... for(j=i;j<=5;j++)         {             printf("%d",j);         }         printf("\n"); return 0; } 3.Number of column - It has 6 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase

print pattern in c - number pattern -1

Print pattern in c - number pattern -1 Write a program to print following pattern 123456 12345 1234 123 12 1 Program code #include <stdio.h> int main() {     int i, j; for(i=6;i>=1;i--) {         for(j=1;j<=i;j++)         {             printf("%d",j);         }         printf("\n");     }     return 0; } Step by Step solution 1. Number of row -    Is has 6 row  , so first loop will execute for 6 time #include <stdio.h> int main() {     int i, j;     for(i=6;i>=1;i--)     {...... }     return 0; } 2. Number of character -  It has only one type of character , so there will be only one nested loop #include <stdio.h> int main() { ...... for(j=1;j<=i;j++)         {             printf("%d",j);         } return 0; } 3.Number of column - It has 6 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row #include <std

Check prime number using recursive function

Check prime number using recursive function Write a program to Check prime number using recursive function #include <stdio.h> #include <conio.h> int n , e ,i ; int prime ( int n , int i) { if (n == 1 || n == 0 ) { return 2; } else { if (i == 1 ) return 0; else { if (n%i != 0){ prime(n , i-1); } else { return 1 ; } } } } int main () { printf("Input a number to check whether number is prime or not: "); scanf("%d" ,&n); e = prime ( n , n-1); if (e == 0 ) printf("\nThe supplied number is prime"); if (e == 1 ) printf("\nThe supplied number is not prime"); if (e == 2 ) printf("\nThe supplied number is neither prime nor not prime"); getch() ; return 0 ; } You can Browse related article below for more information and program code related to recursive function call  Does above is helpful , Post you views in comment DO NOT MISS OTHER C PROGRAMMING TUTORIAL * indicates requi

Sort character of string in ascending or descending order

Sort character of string in ascending or descending order Write a program to sort set of strings in ascending and descending order of their ... char Ascending #include <stdio.h> #include <conio.h> #include <string.h> int main () {     int n , i ,j ;     char name[100] , temp;     scanf("%s", name);     n = strlen(name);     for (i=0 ; i<n ; i++)     {         for(j=i+1 ; j<n ;j++)         {             if(name[i] > name[j])             {             temp = name[i]    ;             name[i] = name[j] ;             name[j] = temp;             }         }     } printf("\n%s" , name); getch() ; return 0 ;    } Descending #include <stdio.h> #include <conio.h> #include <string.h> int main () {     int n , i ,j ;     char name[100] , temp;     scanf("%s", name);     n = strlen(name);     for (i=0 ; i<n ; i++)     {         for(j=i+1 ; j<n ;j++)         {             if(name[i] < name[j])        

File handling in c program - I

Image
Filehandling in c program - I WRITING TO AND READING FROM A FILE #include main() { FILE *f1; char c; printf("Data Input\n\n"); /* Open the file INPUT */ f1 = fopen("INPUT", "w"); /* Get a character from keyboard */ while((c=getchar()) != EOF) /* Write a character to INPUT */ putc(c,f1); /* Close the file INPUT */ fclose(f1); printf("\nData Output\n\n");

Opening a file in c

Image
Opening a file in c A file must be opened before any I/O operation can be performed on that file . The process of establishing a connection between the program and the file is called opening the file A structure named FILE Is defined in the file stdio.h that contains all information about the file like name , status , buffer size , current position , end of file status etc . All these details are hidden from the programmer and the operating system takes care of all these things. typedef struct { …………. …………… } FILE; A file pointer is a pointer to a structure of type FILE . Whenever a file is opened , a structure of type FILE is associated with it , and a file pointer that points to this structure identifies this file . The function fopen() is used to open a file Declaration FILE *fopen (const char *filename , const char *mode); fopen() function takes two string as arguments , the first one is the name of the file to be opened and the second one is the mod

Difference between text file and binary file

Image
Difference between text file and binary file There are two kinds of storing data in file text format and binary format .  In text file data are stored as line of characters with each line terminated by a new line character (‘\n’). In binary format data is stored on the disk in the same way as it is represented in the computer memory . Unix system does not make any distinction between text file and binary file.  Text file are in human readable form and they can be created and read using any text editor , while binary file are not in human readable form and they can be created and read only by specific program written for them . The binary data stored in file can not be read using text editor. The hexadecimal value of 1679 is 0x068f , so in binary format it is represented by two bytes 0x06 and 0x8f . In a text file 1679 is represented by the bytes 0x31 , 0x36 , 0x37 ,0x39 ( ASCII values) . NOTE ASCII value for 1 is 31 and for 9 is 39.  Both text file and binar