You are on page 1of 13

#include<stdio.

h>
#include<conio.h>
struct book
{
char title,author;
int price;
}s;
main()
{
clrscr();
printf("Enter the name of author,title and price of book - \n");
scanf("%s%s%d",s.author,s.title,&s.price);
printf("\nYour Data - \n");
printf("Author =%s,Title =%s,Price=%d",s.author,s.title,s.price);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int a[100],i,n,no,flag=0;
clrscr();
printf("How many numbers ? - ");
scanf("%d",&n);
printf("Enter the elements of array - \n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the number u want to check - ");
scanf("%d",&no);
for(i=0;i<n;i++)
{
if(a[i]==no)
{
flag=0;
break;
}
else
{
flag=1;
}
}
if(flag==1)
{printf("No is absent");
}
else
{printf("No is present");
}
getch();
}
#include<stdio.h>
#include<conio.h>
int main(int argc, char *argv[])
{
int i=0;
printf("argc=%d",argc);
for(i=0;i<argc;i++)
{
printf("argv[%d]=%s\n",i,argv[i]);
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{ char s[100],j,count=0;
clrscr();
printf("Enter a string - ");
scanf("%s",s);
for(j=0;j<strlen(s);j++)
{
if(s[j]=='a'| | s[j]=='e'| | s[j]=='i'| | s[j]=='o' | | s[j]=='u')
{
count++;
}
}
printf("\nTotal number of vowels =%d",count);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{int no;
clrscr();
printf("Enter the number - ");
scanf("%d",&no);
if(no%2==0)
{
printf("\nNo is even");
}
else
{printf("odd");
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{int fact=1,no,no1,rem,ch;
clrscr();
printf("Enter your choice - ");
scanf("%d",&ch);
switch(ch)
{
case 1:
clrscr();
printf("Enter the number - ");
scanf("%d",&no);
while(no>0)
{
fact=fact*no;
no--;
}
printf("Factorial =%d",fact);
break;
case 2:
clrscr();
printf("Enter any 5 digit number - ");
scanf("%d",&no1);
while(no1>0)
{
rem=no1%10;
printf("%d",rem);
no1=no1/10;
}
break;
case 3:
break;
default :
printf("Invalid");
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int t1=0, t2=1, display=0, num;
printf("Enter an integer: ");
scanf("%d",&num);
printf("Fibonacci Series: %d %d ", t1, t2); /* Displaying first two terms */
display=t1+t2;
while(display<num)
{
printf("%d ",display);
t1=t2;
t2=display;
display=t1+t2;
} getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int a, b, c;
clrscr();
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if(a>=b && a>=c)
printf("Largest number =%d", a);
if(b>=a && b>=c)
printf("Largest number =%d", b);
if(c>=a && c>=b)
printf("Largest number =%d", c);
getch();
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char s[20];
int flag=0,i,length;
clrscr();
printf("Enter any string\n");
scanf("%s",s);
length=strlen(s);
for(i=0;i<length/2;i++)
{
if(st[i]!=st[length-1-i])
{
flag=1;
break;
}
}
if(flag==0)
printf("String is Palindrome");
else
printf("String is not palindrome\n");
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int num1,num2,mul,*p1,*p2;
clrscr();
printf("Enter 1st number: ");
scanf("%d",&num1);
printf("Enter 2nd number: ");
scanf("%d",&num2);
p1=&num1;
p2=&num2;
mul=*p1 * *p2;
printf("\n\nProduct of %d and %d is %d",*p1,*p2,mul);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int no,flag=0,i;
clrscr();
printf("Enter the number - ");
scanf("%d",&no);
for(i=2;i<no/2;i++)
{
if(no%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("\n%d is Prime number",no);
}
else
{
printf("\n%d is Not prime number",no);
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
float si;
int p,n,r;
clrscr();
printf("Enter principal amount,rate,number of years - ");
scanf("%d%d%d",&p,&r,&n);
si=(p*n*r)/100;
printf("\nSimple interest =%f",si);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int a[5],j,i,temp;
clrscr();
printf("Enter an array\n");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("Sorted array - \n");
for(i=0;i<5;i++)
{
printf("%d\n",a[i]);
}
getch();
}
//program to find string in reverse order
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,length=0;
char str1[15],str2[15];
clrscr();
printf("Enter a string\n");
scanf("%s",str1);
for(i=0;str1[i]!='\0';i++)
{
length++;
}
printf("Length =%d\n",length);
for(i=0,j=length-1;str1[i]!='\0';i++,j--)
{
str2[i]=str1[j];
}
str2[i]='\0';
printf("Final string =%s\n",str2);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int a[3][3],b[3][3],c[3][3],i,j;
clrscr();
printf("Enter 1st array - \n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter 2nd array - \n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("Substraction of a nd b is- \n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]-b[i][j];
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int k=0,no,i;
clrscr();
printf("Enter the number - ");
scanf("%d",&no);
for(i=0,k=0;i<4;i++)
{
k=k+no%10;
no=no/10;
}
printf("Sum =%d\n",k);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int *a=5,*b=10;
clrscr();
swap(&a,&b);
printf("1st no-%d\n2nd no- %d",a,b);
getch();
}
swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
#include<stdio.h>
#include<conio.h>
main()
{ int i,j,vow=0;
char str[15],v[10]="aeiouAEIOU";
clrscr();
printf("Enter any string\n");
gets(str);
for(i=0;i<10;i++)
{
for(j=0;str[j]!='\0';j++)
{
if(str[j]==v[i])
{
vow++;
}
}
}
printf("Total no. of vowels =%d\n",vow);
getch();
}