C Language Code
C Language Code
Ans:
#include<stdio.h>
void main()
char str[100];
fgets(str,100,stdin);
int length=0;
for(int i=0;str[i]!='\0';i++)
length++;
return length-1;
*write the function countvowel(str)that will count the number of vowels in a given string and written
that count.
Ans:
#include<stdio.h>
#include<string.h>
int countvowel(char str[]);
void main()
char str[80];
fgets(str,80,stdin);
int count=0;
int i;
for(i=0;str[i]!='\0';i++)
if(str[i]=='a'||str[i]=='A'||str[i]=='e'||str[i]=='E'||str[i]=='i'||str[i]=='I'||str[i]=='o'||str[i]=='O'||
str[i]=='u'||str[i]=='U')
count++;
return count;
*write the function reversecase(str)that will change the case of letter in a given string str.
Ans:
#include<stdio.h>
#include<string.h>
char str[80];
gets(str);
reversecase(str);
printf("\n uppercase:%s",str);
int c=0;
while(str[c]!='\0')
str[c]=str[c]-32;
c++;
*write the function replacechar(str,ch1,ch2)that will replace all occurances of character ch1 in a
string str by ch2 and diplay the string in main function.
Ans:
#include<stdio.h>
#include<string.h>
int i=0;
for(i=0;str[i];i++)
if(str[i]==ch1)
str[i]=ch2;
int main()
char str[80],ch1,ch2;
gets(str);
ch1=getchar();
getchar();
ch2=getchar();
replacechar(str,ch1,ch2);
}
*write the function replacewhitespcae(str,ch)that will replace all occurance of whitespace character
in a string str by given character ch.
Ans:
#include<stdio.h>
#include<string.h>
int i=0;
for(i=0;i<str[i];i++)
if(str[i]==' ')
str[i]=ch;
void main()
char str[80],ch;
gets(str);
ch=getchar();
replacewhitespace(str,ch);
*write the function is palindrom(str)that will return true or false depending upon the given string is
palindrom or not.
Ans:
#include <stdio.h>
#include <string.h>
int i, j;
int n = strlen(str);
if (str[i] != str[j])
return 0;
return 1;
int main()
char str[100];
scanf("%s", str);
if (isPalindrome(str))
else
return 0;
}
Ans:
#include<stdio.h>
int main()
int n,count=0;
scanf("%d",&n);
while(n!=0)
count++;
n=n/10;
Ans:
#include<stdio.h>
#include<math.h>
int main()
int sum(int n)
if(n==1)
return 1;
int nm=sum(n-1);
int N=nm+n;
return N;
Ans:
*write a c program to display the quotient and remainder of the division of two variable.
Ans:
#include<stdio.h>
void main()
int n,m;
scanf("%d%d",&n,&m);
int quotient,remiander;
printf("\n quotient=%d,remiainder=%d",n/m,n%m);
}
*write a program to display the size of the different datatypes.
Ans:
#include<stdio.h>
void main()
int inttype;
float floattype;
char chartype;
double doubletype;
*write a c program to swap the value of two variable using bitwise operator(^).
Ans:
#include<stdio.h>
void main()
int a,b;
scanf("%d%d",&a,&b);
a=a^b;
b=b^a;
a=b^a;
}
*write the c program which illustrate the bitwise left shift and right shift operator.
Ans:
#include<stdio.h>
void main()
int n=100,i;
for (i=0;i<=2;++i)
printf("\n ");
for (i=0;i<=2;i++)
*accept dimension of the cylinder and print the surface area and volume.
Ans:
#include<stdio.h>
void main()
float radius,height;
float s_a,v;
scanf("%f%f",&radius,&height);
s_a=2*3.14*radius*(radius+height);
v=3.14*radius*radius*height;
Ans:
#include<stdio.h>
#include<conio.h>
void main()
int a,b,c,i,n;
a=0;
b=1;
scanf("%d",&n);
printf("\n %d \n %d",a,b);
for(i=0;i<n;i++)
c=a+b;
a=b;
b=c;
printf("\n %d",c);
getchar();
*write c program to accept number from user that is n then print all the odd number from n to 1.
Ans:
#include<stdio.h>
int main()
int n;
scanf("%d",&n);
for(int i=n;i>=1;i--)
if(n%2!=0)
i=i-1;
Ans:
#include<stdio.h>
#include<conio.h>
void main()
int x,y;
scanf("%d%d",&x,&y);
swap(&x,&y);
int temp;
temp=*a;
*a=*b;
*b=temp;
Ans:
#include<stdio.h>
void main()
int i,n,fibonacci[30];
scanf("%d",&n);
fibonacci[0]=0;
fibonacci[1]=1;
for(i=2;i<n;i++)
fibonacci[i]=fibonacci[i-1]+fibonacci[i-2];
for(i=0;i<n;i++)
printf("%d \t",fibonacci[i]);
}
or
#include<stdio.h>
void main()
int c[100],n;
scanf("%d",&n);
c[0]=0;
c[1]=1;
for(int i=2;i<n;i++)
c[i]=c[i-1]+c[i-2];
for(int i=0;i<n;i++)
printf("\n %d",c[i]);
*write a c program to accept n number from user and display all even number from n to 1.
Ans:
#include<stdio.h>
#include<conio.h>
void main()
int n;
for(int i=n;i>=1;i--)
if(n%2==0)
i=i-1;
getch();
Ans:
#include<stdio.h>
#include<conio.h>
void main()
int n,i=1;
scanf("%d",&n);
jmp:if(i<=10)
printf("\n %d",i*n);
i++;
goto jmp;
#include<stdio.h>
void main()
int i=1;
jmp:if(i<=10)
printf("\n %d",i);
i++;
goto jmp;
Ans:
#include <stdio.h>
int main() {
int i, j;
printf("\n");
return 0;
}
or
#include<stdio.h>
void main()
int i,n=1;
while(n<=20)
i=1;
while(i<=10)
printf("\n %4d",i*n);
i++;
n++;
printf("\n");
Ans:
#include<stdio.h>
void main()
int i,n=1;
while(n<=10)
i=1;
while(i<=20)
printf("\n %4d",i*n);
i++;
n++;
printf("\n");
or
#include <stdio.h>
int main() {
int i, j;
printf("\n");
}
return 0;
*write a c program to print the sum of the digits of the given number.
Ans:
#include<stdio.h>
void main()
int n,d,sum=0;
scanf("%d",&n);
while(n!=0)
d=n%10;
sum=sum+d;
n=n/10;
printf("\n sum=%d",sum);
*write the c program to count the number of digits in the given number.
Ans:
#include<stdio.h>
void main()
{
int n,count=0;
scanf("%d",&n);
while(n!=0)
count++;
n=n/10;
printf("\n count=%d",count);
Ans:
#include<stdio.h>
void main()
int n,i=1;
scanf("%d",&n);
while(i<=n)
if(n%i==0)
printf("\n %d",i);
i++;
#include<stdio.h>
void main()
int n,i=1,count=0;
scanf("%d",&n);
while(i<=n)
if(n%i==0)
count++;
i++;
if(count==2)
else
Ans:
#include<stdio.h>
int main()
int n,i,sum=0;
scanf("%d",&n);
for(i=1;i<n;i++)
{
if(n%i==0)
sum=sum+i;
if(sum==n)
else
Ans:
#include<stdio.h>
void main()
int n,rev=0,d;
scanf("%d",&n);
while(n!=0)
d=n%10;
rev=rev*10+d;
n=n/10;
Ans:
#include<stdio.h>
void main()
int n,u,rev=0,d;
scanf("%d",&n);
u=n;
while(n!=0)
d=n%10;
rev=rev*10+d;
n=n/10;
if(u==rev)
printf(" %d is a palindrom",u);
else
Ans:
#include<stdio.h>
void main()
int n,count=0;
scanf("%d",&n);
while(n==0)
{
count++;
n=n/10;
*write a c program to accept n number of integer and display their sum and also display their
average.
Ans:
#include <stdio.h>
void main()
int n,m,sum=0;
float avg;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&m);
sum=sum+m;
printf("\n sum=%d",sum);
*write a program to accept n integer and display their greatest and smallest.
Ans:
#include <stdio.h>
int main() {
scanf("%d", &n);
scanf("%d", &num);
scanf("%d", &num);
min = num;
max = num;
return 0;
}
*write a program to accept the integer and display it's digits on separate line.
Ans:
#include<stdio.h>
void main()
int n,d;
scanf("%d",&n);
while(n>0)
d=n%10;
printf("\n %d",d);
n=n/10;
Ans:
#include<stdio.h>
int main()
int n,r,sum=0,temp;
scanf("%d",&n);
temp=n;
while(n>0)
r=n%10;
sum=sum+(r*r*r);
n=n/10;
if(temp==sum)
else
return 0;
or
#include<stdio.h>
int main()
int m,d,s=0,t;
scanf("%d",&m);
t=m;
while(m>0)
d=m%10;
s=s+(d*d*d);
m=m/10;
if(t==s)
}else{
}
return 0;
Ans:
#include<stdio.h>
int main()
int a,b,n=1;
scanf("%d%d",&a,&b);
for(int i=0;i<b;i++)
n=n*a;
return 0;
Ans:
#include<stdio.h>
int main()
int m,n,output=0;
scanf("%d%d",&m,&n);
for(int i=0;i<n;i++)
output=output+m;
return 0;
1 2
1 2 3
Ans:
#include <stdio.h>
int main() {
int n, i, j;
scanf("%d", &n);
printf("\n");
return 0;
}
*write a program to generate following pattern.
Aa
Aa Bb
Aa Bb Cc
Aa Bb Cc Dd
Ans:
#include<stdio.h>
int main()
int n;
char ch='A';
scanf("%d",&n);
for(int i=0;i<=n;i++)
ch='A';
for(int j=1;j<=i;j++)
printf("%c%c ",ch,ch+32);
ch++;
printf("\n ");
return 0;
#include<stdio.h>
int main()
int n,arr[100];
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
int t;
for(int i=0;i<n-1;i++){
for(int j=0;j<n-i-1;j++)
if(arr[j]>arr[j+1])
t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
for(int i=0;i<n;i++)