PSTC QB
PSTC QB
PSTC QB
printf("1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Modulus\n");
printf("Enter your Choice:");
scanf("%d",&x);
switch (x) {
case 1:
printf("The Sum of Two Numbers = %d\n",a+b);
break;
case 2:
printf("The Difference of Two Numbers = %d\n",a-b);
break;
case 3:
printf("The Product of Two Numbers = %d\n",a*b);
break;
case 4:
printf("The Division of Two Numbers = %d\n",a/b);
break;
case 5:
printf("The Remainder of Two Numbers = %d\n",a%b);
break;
default:
printf("Incorrect Input of Choice!\n");
break;
}
}
OUTPUT: Enter the values of a and b:10 6
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Modulus
Enter your Choice:5
The Remainder of Two Numbers = 4
. Write a C program to check whether the given Letter is Vowel or
Consonant.
Ans:
#include <stdio.h>
int main()
{
char ch;
printf("Enter any Alphabet\n");
scanf("%c",&ch);
switch(ch){
case 'a':
printf("%c is a vowel",ch);
break;
case 'e':
printf("%c is a vowel",ch);
break;
case 'i':
printf("%c is a vowel",ch);
break;
case 'o':
printf("%c is a vowel",ch);
break;
case 'u':
printf("%c is a vowel",ch);
break;
//check upper case vowel letters
case 'A':
printf("%c is a vowel",ch);
break;
case 'E':
printf("%c is a vowel",ch);
break;
case 'I':
printf("%c is a vowel",ch);
break;
case 'O':
printf("%c is a vowel",ch);
break;
case 'U':
printf("%c is a vowel",ch);
break;
default:
printf("%c is a consonant",ch);
}
return 0;
}
OUTPUT: Enter any Alphabet
F
F is a consonant
. Write a C program to find the Sum of n natural numbers
Ans: #include <stdio.h>
int main(){
int n,sum=0,i;
printf("Enter the no of Terms:");
scanf("%d",&n);
for (i=1; i<=n; i++) {
sum+=i;
}
printf("The sum of N Natural Numbers is: %d\n",sum);
return 0;
}
OUTPUT: Enter the no of Terms:6
The sum of N Natural Numbers is: 21
. Write a C program to find a factorial of a given Number.
Ans: #include <stdio.h>
int main(){
int i,f=1,number;
printf("Enter a Number:");
scanf("%d",&number);
for (i=1; i<=number; i++) {
f*=i;
}
printf("The Factorial of %d is: %d\n",number,f);
}
OUTPUT: Enter a Number: 5
The Factorial of 5 is: 120
. Write a C program to print Fibonacci numbers.
Ans: #include<stdio.h>
int main()
{
int count, n1 = 0, n2 = 1, n3, i;
printf("Enter the number of terms:");
scanf("%d",&count);
GCD of 98 and 56 is 14
. Write a C program to print the alphabets from A to Z using for loop
Ans: #include <stdio.h>
int main() {
char c;
for (c = 'A'; c <= 'Z'; ++c)
printf("%c ", c);
return 0;
}
Output
ABCDEFGHIJKLMNOPQRSTUVWXYZ
. What is the purpose of ‘for’ loop in C. Demonstrate with an example
program
Ans: The for loop in C language is used to iterate the statements or a part of
the program several times. It is frequently used to traverse the data structures
like the array and linked list.
The syntax of for loop in c language is given below: