Arithemetic Operaters Questions C
Arithemetic Operaters Questions C
#include <stdio.h>
int main(){
char ch;
int a, b, result;
// Asking for Input
printf("Enter an Operator (+, *, *, /): ");
scanf("%c", &ch);
printf("Enter two operands: \n");
scanf("%d %d", &a, &b);
switch(ch){
case '+':
result = a + b;
break;
case '-':
result = a - b;
break;
case '*':
result = a * b;
break;
case '/':
result = a / b;
break;
}
printf("Result = %d", result);
return 0; }
Write a C program to check if an entered character is a vowel or consonant using switch-case
#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");
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;
}
Write a C Program to print first ten natural numbers using while loop.
#include<stdio.h>
int main() {
int i = 1;
while (i <= 10) {
printf(“%d\n”, i);
i++;
}
return (0);
}
Program to print table for the given number using do while loop.
#include<stdio.h>
int main(){
int i=1,number=0;
scanf("%d",&number);
do{
printf("%d \n",(number*i));
i++;
}while(i<=10);
return 0;
}
Write a C program to take an integer number from the user and calculate its factorial & display the result using for
loop.
#include<stdio.h>
int main(){
int i,f=1,num;
scanf("%d",&num);
for(i=1;i<=num;i++)
f=f*i;
return 0;