Posts

Showing posts with the label Learn C Programming

Fibonacci Series In C-Gaurav Pali

Image
 Write a program in C to print the Fibonacci Series Note:- In the Fibonacci series, every next number is the sum of the previous two numbers. #include<stdio.h> #include<conio.h> void main()  {   int a=0,b=1,c,i,n;   clrscr();   printf("Input number of terms you want to print");   scanf("%d",&n);   printf("%d %d ",a,b);   for(i=1;i<=n;i++)    {     c=a+b;     a=b;     b=c;     printf("%d ",c);    }   getch();  } Program ScreenShot OutPut

Count the no of lowercase letters in a text file bca.txt in C

Image
Write a program in C to count the no of lowercase letters in a text file bca.txt This program reads one character at a time by using fgetc() function until the EOF (end of file) returns. Then it checks whether the current character is lowercase or not. If it is a lowercase letter it increments the value of c by 1. It also displays the contents of file named bca.txt. And finally print the total number of lowercase letters present in the file, which is the main purpose to write the program Program #include<stdio.h> #include<conio.h> void main()  {   FILE *fptr;   char ch;   int c=0;   if((fptr=fopen("bca.txt","r"))==NULL)    printf("File doesn't exist\n");   else    {     while((ch=fgetc(fptr))!=EOF)      {       if(ch>=97&&ch<=122) c++;       printf("%c",ch);      }    }    printf("\nTotal lowercase letter in bca.txt file ...

Write A Program In C To Check Whether The No Is Even Or Odd

Image
Write A Program In C To Check Whether The No Is Even Or Odd #include<stdio.h> /* Header file for input/ output functions like                                             scanf(), printf() functions */ #include<conio.h> /* Header file for console functions like clrscr(),                                      getch() functions */ void main()  /* Execution of any program starts at main() function */  {                  /*  main body block begins */     int num;   /* Declare a variable num of integer type */    clrscr();    /* This function is used to clear the console screen */    printf("Enter a number\n"); /* Just a message for a user what to do   ...