0% found this document useful (0 votes)
36 views11 pages

Lab Report Experiment 2

The document contains source code for 4 C programs that take user input and perform comparisons or conditional operations. Program 1 prompts the user to enter a password and checks if it matches a predefined answer. Program 2 subtracts two user-input numbers and identifies if the result is positive or negative. Program 3 compares two user-input numbers and identifies if the first is greater than, less than, or equal to the second. Program 4 uses a switch statement to print different outputs based on whether the user enters 'a', 'b', 'c', or another character. The document also includes source code for 2 additional programs - Program 5 compares two user-input numbers and identifies which is greater or less. Program
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views11 pages

Lab Report Experiment 2

The document contains source code for 4 C programs that take user input and perform comparisons or conditional operations. Program 1 prompts the user to enter a password and checks if it matches a predefined answer. Program 2 subtracts two user-input numbers and identifies if the result is positive or negative. Program 3 compares two user-input numbers and identifies if the first is greater than, less than, or equal to the second. Program 4 uses a switch statement to print different outputs based on whether the user enters 'a', 'b', 'c', or another character. The document also includes source code for 2 additional programs - Program 5 compares two user-input numbers and identifies which is greater or less. Program
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

PART A-1

Source Code

#include <stdio.h>

#include <stdlib.h>

int main() {

int answer=977;

int password;

printf("enter your password: ");

scanf("%d", &password);

if(password == answer){

printf("Correct password \n");

}else{

printf("FAILED ATTEMPT\n");

return 0;

Output

a)

b)

c)
PART A-2

Source Code

#include <stdio.h>

#include <stdlib.h>

int main() {

int first,second,ans;

char *polarity;

printf(" variable x : ");

scanf("%d",&first);

printf("\n variable y: ");

scanf("%d",&second);

ans = first - second;

printf("\n x - y = %d \n", ans);

if(ans >= 0){polarity = "Positive";}

else {polarity = "Negative";}

printf("\n Answer (%d) is a %s number \n", ans, polarity);

printf("Thank you \n");

return 0;

Output

a)
b)

c)
PART A-3

Source Code

#include <stdio.h>

#include <stdlib.h>

int main() {

int x,y;

char *comparison;

printf(" variable x: ");

scanf("%d",&x);

printf("\n variable y: ");

scanf("%d",&y);

if(x > y){comparison = "Greater Than";}

else if(x < y){comparison = "Lesser Than";}

else {comparison = "Equal";}

printf("\n x (%d) is %s y (%d).\n", x, comparison, y);

return 0;

Output

a)
b)

c)

PART A-4

Source Code

#include <stdio.h>

#include <stdlib.h>

int main() {

char alph;
printf(“enter an alpha character: “);

scanf(“%c”,&alph);

switch(alph) {

case ‘a’:

printf(“\n Your entered ‘a’ \n”);

break;

case ‘b’:

printf(“\n Your entered ‘b’ \n”);

break;

case ‘c’:

printf(“\n Your entered ‘c’ \n”);

break;

default:

printf(“\n Your entered other than a/b/c \n”);

break;

printf(“Thank you.\n”);

return 0;

Output
PART B-1

Source Code
#include <stdio.h>

#include <stdlib.h>

int main()

int first,second;

char*comparison;

printf ("This Is The Most EFfectivee Programme To Compare Two Value\n");

printf(" first integer x: ");

scanf("%d",&first);

printf("\n second integer y:");

scanf("%d",&second);

if (first>second){comparison="Greater Than";}

else if (first<second){comparison="Less Than";}

else if (first==second){comparison="Equal";}

printf("\n first (%d) is %s second (%d).\n", first , comparison, second);

return 0;

Output
PART B-2

Source Code
#include <stdio.h>

#include <stdlib.h>

int main() {

char alph;

printf ( "enter an alpha character:");

scanf("%c",&alph);

switch(alph) {

case 'a':

printf("\n Actions speak louder than word \n");

break;

case 'b':

printf("\n Ball is in your court \n");

break;

case 'c':

printf("\n Cross that bridge when you come to it\n");

break;

default:

printf("\n Your entered other than a/b/c \n");

break;

printf("Thank you.\n");

return 0;

Output

You might also like