Professional Documents
Culture Documents
CODE:
#include<stdio.h>
int main()
{ char a;
scanf("%c",&a);
if(a=='a'||a=='e'||a=='i'||a=='O'||a=='u') {
printf("this is a vowel");}
else{
printf("this is a consonent");
return 0; }}
OUTPUT:
Q2. Write a C program to find sum of first N natural number, N must
be taken by the user.
FLOWCHART:
CODE:
#include<stdio.h>
int main()
{
int n,s=0;
printf("enter the number:\n");
scanf("%d",&n);
while(n>0)
{
s=s+n;
n=n-1;
}
printf("the sum is :%d",s);
}
OUTPUT:
Q3. Write a C program to count occurrence of a digit in a number.
FLOWCHART:
CODE:
#include<stdio.h>
scanf("%d",&n);
scanf("%d",&d);
while (n!=0){
i = n%10;
if (d == i ){
c = c + 1;}
n = n / 10 ;}
printf("repetition is : %d",c);
return 0; }
OUTPUT:
Q4. Write a C program to read an integer and print its
multiplication table.
F LOWCHART:
CODE:
#include<stdio.h>
int main()
{
int n;
printf("enter the number :\n");
scanf("%d",&n);
for(int i=0;i<11;i++)
{
printf("%d X %d=%d\n",n,i,n*i);
}
return 0;
}
OUTPUT:
Q. 5. Write a C program to Display Characters from A to Z
Using Loop.
FLOWCHART:
CODE:
#include<stdio.h>
int main()
printf("%c ",a);
return 0;
OUTPUT:
Q6. Write a C program to enter numbers until the user wants. At the
end, display the total number of positive, negative and zeros entered.
FLOWCHART:
CODE:
#include<stdio.h>
int main (){
int i,n = 0,m = 0 ;
while (1){
printf("Enter a number ");
scanf("%d",&i);
if (i<0){
n = n + 1;}
else if ( i> 0 ){
m = m + 1;}
else
{break;}}
printf("Positive no. are %d ",n);
printf("Negative no. are %d ",m);
return 0;}
OUTPUT:
Q7. Write a C program to multiply two numbers using plus operator.
FLOWCHART:
CODE:
#include<stdio.h>
int main (){
float n1,n2,mul;
printf("Enter n1: ");
scanf("%f",&n1);
printf("Enter n2: ");
scanf("%f",&n2);
for (int i = 1;i <= n2;i++){
mul = mul + n1;
}
printf("The product is : %f",mul);
return 0 ;
OUTPUT:
Q. 8. Write a C program to read weekday number and print weekday
name using switch.
FLOWCHART:
CODE:
#include<stdio.h>
int main()
{
int d;
printf("enter the day no.");
scanf("%d",&d);
switch(d)
{
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday"); OUTPUT:
break;
case 6:
printf("Saturday");
break;
case 7:
printf("Sunday");
break;
default:
printf("wrong input");
break;
}
return 0 ;
}
Q9. Write a C program to generate all the prime numbers between 1
and n, where n is a value supplied by the user.
FLOWCHART:
CODE:
#include<stdio.h>
int main()
{
int n,i,j;
printf("enter the number:");
scanf("%d",&n);
for(j=2;j<n;j++)
{
for(i=2;i<j;i++)
{
if(j%i==0)
break;
}
if(i==j)
{
printf("%d ",i);
}}
return 0;
}
OUTPUT:
Q10. Write a program to compute up to N terms:
1+x+(x^2)/2! +(x^3)/3!....
FLOWCHART:
CODE:
#include<stdio.h>
int main()
{
int x,n;
float sum,row;
printf("Enter x = ");
scanf("%d",&x);
printf("Enter the number of terms:");
scanf("%d",&n);
sum =1;
row=1;
for(int i=1;i<n;i++)
{
row=row*x/(float)i;
sum=sum+row;
}
printf("the sum is :%f",sum);
return 0;
}
OUTPUT: