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

Arithemetic Operaters Questions C

The document contains code snippets for C programs that use different loops and control structures like switch case. The programs include: 1. A basic calculator program that takes input from the user and performs basic operations like addition, subtraction etc. using switch case. 2. A program to check if an entered character is a vowel or consonant using switch case. 3. Programs to print first 10 natural numbers using while loop, print a table for a given number using do-while loop, and calculate factorial of a number taken from user using for loop.

Uploaded by

kunal200jee
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Arithemetic Operaters Questions C

The document contains code snippets for C programs that use different loops and control structures like switch case. The programs include: 1. A basic calculator program that takes input from the user and performs basic operations like addition, subtraction etc. using switch case. 2. A program to check if an entered character is a vowel or consonant using switch case. 3. Programs to print first 10 natural numbers using while loop, print a table for a given number using do-while loop, and calculate factorial of a number taken from user using for loop.

Uploaded by

kunal200jee
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Write a C program to design calculator with basic operations (+,-,*,/,%) using switch-case.

#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;

printf("Enter a number: ");

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;

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;

You might also like