Friday, October 23, 2015

C program to convert given upper case letters to lower case

This C program will convert given uppercase letters into lover case.

#include<stdio.h>
#include<string.h>
int main()
{
  char str1[10]="ABCD";
  int i;
  for(i=0; i<4; i++)
  {
    printf("%c",str1[i]+32);
  }
  return 0;
}

Output of the program:

abcd

Friday, October 9, 2015

C program to demonstrate use of Username and Password (login id password) functionality.

Login ID Password Program


// Username and Password (LoginID Password) functionality using C.
// Username: student
// Password: guest

#include<stdio.h>
#include<string.h>
int main()
{
 int i;
 char ch1, username[10], password[10];

 printf("Enter your Username:");
 gets(username);
 
 printf("Enter your Password:");
 gets(password);
 
 if(strcmp(username,"student")==0 && strcmp(password,"guest")==0)
  printf("\n Welcome....\n MENU...Main Logic of Program..");
 else
  printf("Invalid Username/Password.");
 return 0;
}

Output of Program

Enter your Username:student
Enter your Password:guest

 Welcome....

 MENU...Main Logic of Program..

 



Pattern : C program to print Hollow Square for given value N.

This program will print hollow square pattern.
 
#include<stdio.h>
int main()
{
 int i,j,n=5;
 //for loop to print line 1
 for(i=0; i<n;i++)
 {
  printf("* ");
 }
 printf("\n");
 
 // logic for repeating line 2 to 4, n-2 times
 for(j=0; j<n-2; j++)
 {
 //for loop to print *    * line 2 to 4
  printf("* ");
 
  for(i=0; i<n-2; i++)
   printf("  ");
 
  printf("*\n");
 }
 for(i=0; i<n;i++)
 {
  printf("* ");
 }
  return 0;
}

Output of the program

* * * * *
*       *
*       *
*       *
* * * * *

Pattern : C program to print Square pattern based on given value N.

This program will print Square pattern based on given value of N. 

#include<stdio.h>
int main()
{
 int i,j, n=5;
 //Logic to print square based on given value of N... 
 
 for(i=0; i<n; i++)
 {
  for(j=0; j<n; j++)
   printf("* "); //one space in printf prints proper output
  printf("\n");
 }
 return 0;
}

Output of the program

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *