C Program to read text File on Disk using FREAD function

C Program to read text File on Disk using FREAD function 


Its Basic C Program to read any text from disk using FRead Function which belongs to stdio.h, using this function with file pointers you can read the TEXT contents of any file. 

#include 
#include 

int main()
{
    int cur_char;
    FILE *out_file;

    out_file = fopen("test.txt", "w");
    if (out_file == NULL) {
        fprintf(stderr,"Can not open output file\n");
        exit (8);
    }

    for (cur_char = 0; cur_char < 128; ++cur_char) {
        fputc(cur_char, out_file);
    }
    fclose(out_file);
    return (0);
}




C Program accept 10 values and sort them

C Program accept 10 values and sort them


#include
#include
 void main()
 {
  int num[10],i,j,temp;
  clrscr();
  printf("\n Enter 10 values of an array...........\n");
  for(i=0;i<10;i++)
   scanf("%d",&num[i]);

 printf("\n array before sort .........\n");
  for(i=0;i<10;i++)
   printf("%d\t",num[i]);

 for(i=0;i<9;i++)
 {
  for(j=i+1;j<10;j++)
  {
   if(num[i]<num[j])
   {
    temp=num[i];
    num[i]=num[j];
    num[j]=temp;
   }
  }
 }

 printf("\n array after sort .........\n");
  for(i=0;i<10;i++)
   printf("%d\t",num[i]);

   getch();
  }




C Program to find Sum of Series using Function

C Program to find Sum of Series using Function



#include
#include
long int sum_sqr(int);
main()
 {
  int n;
  clrscr();
  printf("\n Enter any number : ");
  scanf("%d",&n);
  printf("\n Sum of Series is %ld",sum_sqr(n));
  printf("\n\n Press any key to exit. . .");
  getch();
}

 long int sum_sqr(int m)
 {
  if(m<=1)
   return 1;
  else
   return (m*m+sum_sqr(m-1));
  }

C Program to calculate Sum and Average of Marks and validate also

C Program to calculate Sum and Average of Marks and validate also


#include
#include
main()
{
 int m[5],i,sum=0,avg;
 clrscr();
 printf("Enter the marks of five subjects=");
 for(i=0;i<=4;i++)
 {
  scanf("%d",&m[i]);
 }
 for(i=0;i<=4;i++)
 {
  if(m[i]>100)
  {
   printf("Invalid\n");
   break;
  }
  else
  {
   sum=sum+m[i];
  }
 }
 printf("Sum=%d\n",sum);
 avg=sum/5;
 printf("Avg=%d",avg);
 getch();
}


C While Loop Program to show Difference Between Pre-Increment and Post-Increment

C While Loop Program to show Difference Between Pre-Increment  and Post-Increment 



#include

 int main(void) {
  int i;
 
  i = 0;
  while(i++ < 5) {
   printf("%d\n", i);
  }
  printf("\n");
  i = 0;
  while(++i < 5) {
   printf("%d\n", i);
  }
  return 0;
 }



C Program to show Example of While .. Continue

C Program to show Example of While .. Continue 




#include

 int main()
 {
  int i;

  i = 0;
       while ( i < 20 )
       {
            i++;
            
            printf(" to see\n");
continue;
printf("Nothing to see\n");
       }
       return 0;
 }


C Program to print 1 to 10 Numbers using While and Break

C Program to print 1 to 10 Numbers using While and Break


#include

 int main()
 {
       int i;

  i = 0;
  while ( i < 20 )
       {
            i++;
            if ( i == 10)
                 break;
       }
       return 0;
 }