Posts

Showing posts from August, 2016

Printing a shape with space Pattern using C

Image
#include<stdio.h> void main() { int i,j,m; printf("Enter the height  of the pattern : "); scanf("%d",&m); for(i=0;i<m;i++) { for(j=0;j<m;j++) { if(i==0 || i==m-1) printf(" * "); else if(j==0 || j==m-1) printf(" * "); else if(i==j) printf(" $ "); else printf("   "); } printf("\n"); } } o/p :

Display pattern using C

/* Write a program to display the following pattern ABCDEDCBA ABCD   DCBA ABC         CBA AB               BA A                     A */ #include<stdio.h> void main() { char ch; int i,j,m; printf("Enter the height of the pattern " ); scanf("%d",&m); for(i=0;i<=m/2;i++) { ch='A'; for(j=0;j<m;j++) { if(j>m/2-i && j<m/2+i) printf(" "); else printf("%c",ch); if(j>=m/2) ch--; else ch++; } printf("\n"); } }

code for accessing File in C

/*This code will create one file with name Source.txt then copy only consonants into another file named as Target.txt*/ #include<stdio.h> void main() { FILE *fp,*fp1; char ch; fp=fopen("Source.txt","w+"); while((ch=getche())!=13) { fputc(ch,fp); } fclose(fp); fp=fopen("Source.txt","r"); fp1=fopen("target.txt","w+"); while((ch=fgetc(fp))!=EOF) { if(ch!='a' && ch!='e' && ch!='i' && ch!='o' && ch!='u') fputc(ch,fp1); } fclose(fp1); }