void main ()
{
int no[5],i,sum;
clrscr ();
for (i=0;i<=4;i++)
{
printf ("Enter Element: ");
scanf ("%d",&no[i]);
}
sum=no[0]+no[1]+no[2]+no[3]+no[4];
printf ("\nSum of five Elements: %d",sum);
getch ();
}
WAP to print the detail of the programmer
if the given number is 464
void main ()
{
int pass;
clrscr();
do
{
printf ("Enter Password to see the detail of programmer:\n");
scanf ("%d",&pass);
}
while (pass!=464);
printf ("\nJagjeet Singh");
printf ("\nB.Sc. (I.T.)\nPunjab
getch ();
}
WAP to print series from 1 to 10 and skip 5 & 7
void main ()
{
int a;
clrscr ();
for (a=1;a<=10;a++)
{
if (a==5 || a==7)
continue;
printf ("%d\n",a);
}
getch ();
}
void main ()
{
int i=0,count=0;
clrscr ();
for(i=0;i<=255;i++)
{
if (count>24)
{count=0;getch();}
else
{printf("%d=%c\n",i,i);
count++;}
}
getch ();
}
Click on image to enlarge it
void main ()
{
char str [20];
clrscr ();
printf ("Enter your name: ");
gets (str);
printf("\nLength is : %d",strlen(str));
printf("\nUpper is : %s",strupr(str));
printf("\nLower is : %s",strlwr(str));
printf("\nReverese is : %s",strrev(str));
getch ();
}
WAP to enter records and also repeat the step if user wants to continue
void main ()
{
char nm [20],cls[10];
int rollno,m1,m2,m3,tm;
float per;
char ch;
clrscr ();
do
{
printf ("\nEnter Marks of Hindi: ");
scanf ("%d",&m1);
printf ("Enter Marks of Pbi : ");
scanf ("%d",&m2);
printf ("Enter Marks of Math : ");
scanf ("%d",&m3);
tm=m1+m2+m3;
per=(tm*100)/300;
printf ("\nTotal Marks are %d",tm);
printf ("\nPercentage is %.2f",per);
printf ("\nDo you want to continue Y/N: ");
fflush(stdin);
scanf ("%c",&ch);
}
while (ch=='y' || ch=='Y');
getch ();
}
WAP to create double dimension array of 2x3 matrix and display its Elements
{
int a[2][3],i,j;
clrscr ();
for (i=0;i<2;i++)
{
for (j=0;j<3;j++)
{
printf ("\nEnter element: ");
scanf ("%d",&a[i][j]);
}
}
for (i=0;i<2;i++)
{
for (j=0;j<3;j++)
{
printf ("%d\t",a[i][j]);
}
printf ("\n");
}
getch ();
}
WAP to count number of vowels
void main ()
{
char s[20],vw=0,i;
clrscr();
printf ("Enter any string: ");
gets (s);
for (i=0;i<=strlen(s);i++)
{
switch (s[i])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
vw++;
}
}
printf ("There are %d vowels in it",vw);
getch ();
}
void main ()
{
char *str,*str1;
clrscr ();
printf("Enter your name: ");
gets (str);
str1="jeet";
strcat(str,str1);
printf("\n %s",str);
getch ();
}
WAP to find amount of given quantity of any company with 10% discount using switch case
void main()
{
int,ch qty;
long tb,dis,nb;
clrscr();
printf("1.BPL\n2.Onida\n3.Sony\n4.Samsung\n5.LG\n");
printf("\nEnter Your Choice: ");
fflush(stdin);
scanf("%d",&ch);
printf("Enter Qty: ");
scanf("%d",&qty);
switch(ch)
{
case 1:tb=(long)qty*10000;
printf("\nBPL is %ld",tb);
break;
case 2:tb=(long)qty*12000;
printf("\nOnida is %ld",tb);
break;
case 3:tb=(long)qty*11500;
printf("\nSony is %ld ",tb);
break;
case 4:tb=(long)qty*11000;
printf("\nSamsung is %ld ",tb);
break;
case 5:tb=(long)qty*13000;
printf("\nLG is %ld ",tb);
break;
Default:
printf("Wrong Choice...");
}
dis=(tb*10)/100;
nb=tb-dis;
printf("\nDiscount is %ld",dis);
printf("
\nNet bill is %ld",nb);
getch();
}
void main()
{
int a;
float b;
double c;
char ch;
long d;
char nm[10];
clrscr();
printf("\nInt size is \t:%d", sizeof (a));
printf("\nFloat size is \t:%d", sizeof (b));
printf("\nDouble size is \t:%d", sizeof (c));
printf("\nChar size is \t:%d", sizeof (ch));
printf("\nLong size is \t:%d", sizeof (d));
printf("\nString size is \t:%d", sizeof (nm));
getch ();
}
WAP to find the factorial of the number
void main ()
{
int fact=1,no;
clrscr();
printf ("Enter any number: ");
scanf ("%d",&no);
do
{
fact=fact*no;
no--;
}
while (no>0);
printf ("\nFactorial is %d",fact);
getch ();
}
WAP to print series from 1 to 10 & find its
void main ()
{
int a=1,sqr=0,cube=0;
clrscr ();
while (a<=10)
{
sqr=pow(a,2);
cube=pow(a,3);
printf ("%d\t %d\t %d\n",a,sqr,cube);
a++;
}
getch ();
}
WAP to print series from 20 to 1
#include
void main ()
{
int a;
clrscr ();
a=20;
while (a>=1)
{
printf ("\n%d",a);
a--;
}
getch ();
}
void main ()
{
int a;
clrscr ();
a=1;
while (a<=20)
{
if (a%2==1)
printf ("\n%d",a);
a++;
}
getch ();
}
#include
void main ()
{
int no,r,res,temp=0;
clrscr ();
printf ("Enter Number: ");
scanf ("%d",&no);
r=res=0;
temp=no;
while (no>0)
{
r=no%10;
no=no/10;
res=(res*10)+r;
}
if (temp==res)
printf("Number is Palandrom");
else
printf("Number is not Palandrom");
getch ();
}
WAP to find out Total Bill with discount according to conditions (Ternary Operators)
void main ()
{
int b,dis,n;
clrscr ();
printf ("Enter Bill: ");
scanf ("%d",&b);
dis=(b<500)?(b*.10):(b>=500 && b<1000)?(b*.15):(b>=1000 && b<=2000)?(b*.20):(b*.25);
n=b-dis;
printf ("Net Bill is %d",n);
getch();
}
WAP to find out Bigger & Equal number from three numbers
(Ternary Operators)
void main ()
{
int a,b,c;
clrscr ();
printf ("Enter the value of A: ");
scanf("%d",&a);
printf ("Enter the value of B: ");
scanf ("%d",&b);
printf ("Enter the value of C: ");
scanf ("%d",&c);
(a>b && a>c)?printf("A is Big"):(b>a && b>c)?printf("B is Big"):(a==b && b==c)?printf("All are Eqaul"):printf("C is Big");
getch ();
}