You are on page 1of 4

1.

Write a program that asks user an arithmetic operator ('+','-','*', '/',%) and two operands and
perform the corresponding calculation on the operands.

#include <stdio.h>
#include <conio.h>
void main()
{
int a, b, c;
char ch;
clrscr() ;
printf("Enter your operator(+, -, /, *, %)\n");
scanf("%c", &ch);
printf("Enter the values of a and b\n");
scanf("%d%d", &a, &b);

switch(ch)
{
case '+': c = a + b;
printf("addition of two numbers is %d", c);
break;
case '-': c = a - b;
printf("substraction of two numbers is %d", c);
break;
case '*': c = a * b;
printf("multiplication of two numbers is %d", c);
break;
case '/': c = a / b;
printf("remainder of two numbers is %d", c);
break;
case '%': c = a % b;
printf("quotient of two numbers is %d", c);
break;
default: printf("Invalid operator");
break;
}
getch();
}
2. Write a program which takes a text input and count total number of vowels,
consonants and other special characters and print the result?
#include <stdio.h>

int main()
{
char line[150];
int i, vowels, consonants, digits, spaces;

vowels = consonants = digits = spaces = 0;

printf("Enter a line of string: ");


scanf("%[^\n]", line);

for(i=0; line[i]!='\0'; ++i)


{
if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
line[i]=='o' || line[i]=='u' || line[i]=='A' ||
line[i]=='E' || line[i]=='I' || line[i]=='O' ||
line[i]=='U')
{
++vowels;
}
else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
{
++consonants;
}
else if(line[i]>='0' && line[i]<='9')
{
++digits;
}
else if (line[i]==' ')
{
++spaces;
}
}

printf("Vowels: %d",vowels);
printf("\nConsonants: %d",consonants);
printf("\nDigits: %d",digits);
printf("\nSpaces: %d", spaces);

return 0; }
3. Write a program which takes 10 integers as input and prints the largest one.
#include <stdio.h>

void main()
{
int i=0;
int largestNum,tempNum;
printf("Enter number[%d]:",++i);
scanf("%d",&tempNum);
largestNum=tempNum;
while(i<10)
{
printf("Enter number[%d]:",i+1);
scanf("%d",&tempNum);
if(tempNum>largestNum)
largestNum=tempNum;
i++;
}
printf("\nLargest number is : %d\n",largestNum);
}

You might also like