C Program to Find the Number of Vowels, Consonants, Digits and White space in a String

#include
int main(){
char line[150];
int i,v,c,ch,d,s,o;
o=v=c=ch=d=s=0;
printf(“Enter a line of string:\n”);
gets(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’)
++v;
else if((line[i]>=’a’&& line[i]=’A’&& line[i]=’0’&&c<='9')
++d;
else if (line[i]==' ')
++s;
}
printf("Vowels: %d",v);
printf("\nConsonants: %d",c);
printf("\nDigits: %d",d);
printf("\nWhite spaces: %d",s);
return 0;
}

A calculator program

#include
#include

int main(){
int num1, num2, choice;

printf(“Choose an operation\n\n”);
printf(“[1] Add\n[2] Subtract\n[3] Multiply\n[4] Divide\n[5] Exit\n”);
scanf(“%d”, &choice);

switch(choice){
case 1:
printf(“Enter 1st number:\n”);
scanf(“%d”, &num1);
printf(“Enter 2nd number:\n”);
scanf(“%d”, &num2);
printf(“\n%d”, (num1+num2));
break;
case 2:
printf(“Enter 1st number:\n”);
scanf(“%d”, &num1);
printf(“Enter 2nd number:\n”);
scanf(“%d”, &num2);
printf(“\n%d “, (num1-num2));
break;
case 3:
printf(“Enter 1st number:\n”);
scanf(“%d”, &num1);
printf(“Enter 2nd number:\n”);
scanf(“%d”, &num2);
printf(“\n%d”, (num1*num2));
break;
case 4:
printf(“Enter 1st number:\n”);
scanf(“\n%d”, &num1);
printf(“Enter 2nd number:\n”);
scanf(“%d”, &num2);
printf(“\n%d”, (num1/num2));
break;
case 5:
return 0;
default:
printf(“That is not a valid choice.”);
break;
}
return 0;
}