Program to print the given pattern using nested loop
Example Program: To print the following pattern:-** ** * ** * * * #include<stdio.h> main() { int i,j; for(i=1;i<=4;i++) { for(j=1;j<=i;j++) { printf("*\t"); } printf("\n"); } } Output:
Programs using for loop
Example Program 1: To find the sum of the digits of the given number using for loop. #include<stdio.h> main() { int m,i=1,k=0,y,p; printf("\nEnter any value :
Program to separate even and odd numbers in a file
Program to read numbers from a file “data” which contains a series of integer numbers and then write all odd
Program to change letters case in a file
Program to change all upper-case letters in a file to lower case letters and vice versa. #include<stdio.h> main() { FILE *fp1,*fp2; char c; fp1=fopen("text.txt","r"); fp2=fopen("copy.txt","w"); while((c=getc(fp1))!=EOF) { if(c>=65&&c<=91) c=c+32; else c=c-32; putc(c,fp2); } fcloseall(); } Output:
Program to add content to a file
Program to add content to a file and display the content before and after adding to a file. #include<stdio.h> #include<conio.h> main() { FILE *fp1,*fp2; char s,c; clrscr(); printf("\n\n\t
Program for copying file contents to another file
#include<stdio.h> main() { FILE *fp1,*fp2; char s; fp1=fopen(“input.txt”,”r”); fp2=fopen(“output.txt”,”w”); while ((s=getc(fp1))!=EOF) putc(s,fp2); fclose(fp1); fclose(fp2); } Output:
Program to count the number of statement terminators and opening braces
Program to read a C program and count the number of statement terminators and the number of opening braces. #include<stdio.h> main() { FILE *fp; int
Program to read data from input file and display on monitor
Program to read data from input file and place first 10 characters in an array and display on the monitor. #include<stdio.h> main() { FILE
File program to read and encrypts character
program to read a character file and encrypts it by replacing each alphabet by its next alphabet cyclically i.e., z
program for one member used at a time in union
#include <stdio.h> #include <string.h> union Data { int i; float f; char str[20]; }; int main( ) { union Data data; data.i = 10; printf( "data.i : %d\n", data.i);data.f =