Category: Programming Examples in C
Write a program in C that perform login operation. The program will accept username and password as a string from the user. The valid username should be “user” and the valid password should be “default”. If either of the username or password is incorrect then it should display the appropriate message. If username and password entered is correct, then it should display the message “User successfully logged in…”. Here is the C program: #include<stdio.h> #include<conio.h> #include<string.h> void main() { char *username; char *password; clrscr(); printf(“Enter the username: “); gets(username); printf(“\nEnter the password: “); gets(password); if(strcmp(username, “user”) == 0){ //username verification...
The below program in C will find out weekday based on the weekday number input. We will be following the below logic. 1 -> Sunday 2 -> Monday 3 -> Tuesday 4 -> Wednesday 5 -> Thursday 6 -> Friday 7 -> Saturday Here we are accepting the week day number as input from the user and use switch statement to display the weekday. Below is the program in C. #include<stdio.h> #include<conio.h> void main(){ int day; clrscr(); printf(“Enter the day number: “); scanf(“%d”, &day); switch(day){ case 1: printf(“\nIts Sunday”); break; case 2: printf(“\nIts Monday”); break; case 3: printf(“\nIts Tuesday”); break;...
C program that converts lowercase character to its uppercase equivalent and displays it Explanation Step 1: Read the lowercase character Step 2: Convert the lowercase character to its uppercase by using the library function toupper() Step 3: Display the converted uppercase character Note: The function toupper() used in this program is a library function which is generally included in the header file ctype.h and the purpose of this function is to convert the lowercase letter to its uppercase. #include<stdio.h> #include<ctype.h> void main() { char lower, upper; lower = getchar(); upper = toupper(lower); putchar(upper); } Output: l L
Below is the C program that reads a line of text into the computer and then writes back out in its original form Explanation Step 1: Read the line of text by using the library function gets() and store it in an array Step 2: Display the read line by using the library function puts() Program: #include<stdio.h> void main() { char line[80]; gets(line); puts(line); } Output: Learn C Online is the best tutorial website to learn C Learn C Online is the best tutorial website to learn C
The below program in C will accepts the radius of a circle from the user and calculates its area and displays the calculated result to the user on the screen. Explanation Step 1: Read the radius Step 2: Calculate the area by applying the formula: Area = (pi)*r2 = 3.14 * r2 #include<stdio.h> #include<conio.h> void main() { float radius, area; printf(“Radius = ?”); scanf(“%f”, &radius); //calculate the area area = 3.14 * radius * radius; //display the calculated result printf(“Area = %f”, area); getch(); } Output: Radius = ?5 Area = 78.500000
A character is entered through the keyboard. Below is a program to determine whether the character entered is a capital letter, a small case letter, a digit or special symbol. We will make use of isupper(), islower() and isdigit() functions to write this C Program. isupper() – This function will take character as parameter and will return true if the character is UPPERCASE. islower() – This function will take character as parameter and will return true if the character is lowercase. isdigit() – This function will take character as parameter and will return true if the character is a digit else it will return...