ASSIGNMENT-3 Introduction To Computing Lab (Batch-F3)
ASSIGNMENT-3 Introduction To Computing Lab (Batch-F3)
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.
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;
/* 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;
scanf("%d",&num);
for(i=1;i<=num;i++)
f=f*i;
return 0;
}
Introduction to Computing Lab (Batch-F3)
Program 4:
#include <stdio.h>
int main(){
scanf("%d", &Num);
while (Num != 0)
{
remainder = Num % 10;
rev_Num = rev_Num * 10 + remainder;
Num = Num/10;
}
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: