0% found this document useful (0 votes)
42 views

ASSIGNMENT-3 Introduction To Computing Lab (Batch-F3)

The document contains 4 programming assignments for a computing lab. The first program uses a switch case to check if a character entered by the user is a vowel or consonant. The second program prints all numbers from 2 to 100 that are divisible by both 2 and 3. The third program takes a number input and calculates its factorial. The fourth program reverses a number entered by the user. For each program, the document provides the aim, algorithm, flowchart and C code implementation.

Uploaded by

1224 OZEAR KHAN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

ASSIGNMENT-3 Introduction To Computing Lab (Batch-F3)

The document contains 4 programming assignments for a computing lab. The first program uses a switch case to check if a character entered by the user is a vowel or consonant. The second program prints all numbers from 2 to 100 that are divisible by both 2 and 3. The third program takes a number input and calculates its factorial. The fourth program reverses a number entered by the user. For each program, the document provides the aim, algorithm, flowchart and C code implementation.

Uploaded by

1224 OZEAR KHAN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Introduction to Computing Lab (Batch-F3)

Assignment.No:03 Student ID: 211001001224


Name: OZEAR KHAN
Date: 21.02.2022

Aim:
Program 1: Write a C program to take a number as input from the user and find out
whether it is a vowel or a consonant using switch-case.

Program 2: Write a C program that displays all the numbers from 2 to 100 that are
divisible by 2 as well as by 3.

Program 3: Write a C program to take a number as input from the user and find out its
factorial.

Program 4: Write a C program to print a number in reverse order.

Algorithm:
Program 1:

Step 1: Start
Step 2: Input n
Step 3: If n=='a' or n=='e' or n=='i' or n=='o' or n=='u' then goto to Step 4 else goto Step 5
Step 4: Print('vowel') goto Step 6
Step 5: Print ('consonant ')
Step 6: End.

Program 2:

Step 1: Start
Step 2: Declare int i as looping variable. Then
Step 3: for (i=2; i<100; i++), this goes from 2 to 100.
Step 4: now check if the number is divisible by 2 and 3 as well, by if-statement.
Step 5: if True print the numbers, if false increment i and check another number.
Step 6: End.
Introduction to Computing Lab (Batch-F3)

Program 3:

Step 1: Start
Step 2: Read number num.
Step 3: Initialize f to 1.
Step 4: for(i=1;i<=num;i++), this goes from 1 to user input number num.
Step 5: f=f*I; to calculate the factorial of the user input number.
Step 6: Print Factorial of user input number.
Step 7: Return 0
Step 8: End.

Program 4:

Step 1: Start
Step 2: We will declare two int variables: ‘Number’ store the number to be reversed, and
‘Reversed_Number,’ initialized to be 0, will hold the resultant reversed number.
Step 3: Now, we will use the formula Reversed_Number = Reversed_Number*10 +
Number%10.
Step 4: This formula divides the number by 10 and stores the remainder multiplied by 10
as the value of the ‘Reversed_Number.’
Step 4: After applying the formula, we will divide the number by 10 and update its value to
eliminate the last digit that is already reversed.
Step 5: We will repeat this until the value of the number becomes less than 0.
When the number goes below 0, the ‘Reversed_Number’ variable will have the
result.
Step 6: End.
Introduction to Computing Lab (Batch-F3)

Flowchart:
Program 1:
Introduction to Computing Lab (Batch-F3)

Program 2:
Introduction to Computing Lab (Batch-F3)

Program 3:
Introduction to Computing Lab (Batch-F3)

Program 4:
Introduction to Computing Lab (Batch-F3)

Programs:
Program 1:
#include <stdio.h>
int main()
{
char ch;

/* Input an alphabet from user */


printf("Enter any alphabet: ");
scanf("%c", &ch);

/* Switch value of ch */
switch(ch)
{
case 'a':
printf("Vowel");
break;
case 'e':
printf("Vowel");
break;
case 'i':
printf("Vowel");
break;
case 'o':
printf("Vowel");
Introduction to Computing Lab (Batch-F3)

break;
case 'u':
printf("Vowel");
break;
case 'A':
printf("Vowel");
break;
case 'E':
printf("Vowel");
break;
case 'I':
printf("Vowel");
break;
case 'O':
printf("Vowel");
break;
case 'U':
printf("Vowel");
break;
default:
printf("Consonant");
}

return 0;
}
Introduction to Computing Lab (Batch-F3)

Program 2:

#include<stdio.h>
int main()
{
int i; /* looping variable */
for(i=2;i<=100;i++) /* goes from 2 to 100 */
{
if((i % 2 == 0) && (i % 3 == 0)) /* checks all three conditions */
{
printf("%d ",i);
}
}
printf("\nEnd of Program"); /* End */
}
Introduction to Computing Lab (Batch-F3)

Program 3:

#include<stdio.h>

int main()

int i,f=1,num;

printf("Enter a number: ");

scanf("%d",&num);

for(i=1;i<=num;i++)

f=f*i;

printf("Factorial of %d is: %d",num,f);

return 0;
}
Introduction to Computing Lab (Batch-F3)

Program 4:
#include <stdio.h>

int main(){

int Num, rev_Num = 0, remainder;

printf("Enter the number to reverse: ");

scanf("%d", &Num);

while (Num != 0)
{
remainder = Num % 10;
rev_Num = rev_Num * 10 + remainder;
Num = Num/10;
}

printf("The reversed number is: %d", rev_Num);

return 0;

}
Introduction to Computing Lab (Batch-F3)

Output Screenshots:
Program 1:
Introduction to Computing Lab (Batch-F3)

Program 2:
Introduction to Computing Lab (Batch-F3)

Program 3:
Introduction to Computing Lab (Batch-F3)

Program 4:

You might also like