Question B.2.
#include
main()
{
int num,i,new1,x;
int val[5];
for(i=0;i<=5;i++)
{
printf("Enter the value ");
scanf("%d",&val[i]);
}
for(i=0;i<=5;i++)
{
printf("%d\t",val[i]);
}
printf("Enter Value place:");
scanf("%d",&new1);
printf("Enter Value :");
scanf("%d",&x);
val[new1]=x;
for(i=0;i<=5;i++)
{
printf("%d\n",val[i]);
}
}
begin
Sunday, December 14, 2008
Exam Paper :Answers
Posted by
BADTNC
at
11:10 PM
0
comments
Labels: C Programming
Finding the Vowels and the Letter Count in a Sentence
#include
void main()
{
int x,count=0,a=0,e=0,i=0,o=0,sp=0,u=0,total=0;
char str[1000];
printf("Enter a Word : ");
gets(str);
for(x=0;str[x]!=0;x++)
{
switch (str[x])
{
case ' ': sp++;break;
case 'a': a++; break;
case 'e': e++; break;
case 'i': i++; break;
case 'o': o++; break;
case 'u': u++; break;
default: count++;
}
total=a+e+i+o+u+count;
}
printf("\nSpaces count: %d",sp);
printf("\nNumber of a's %d",a);
printf("\nNumber of e's %d",e);
printf("\nNumber of i's %d",i);
printf("\nNumber of o's %d",o);
printf("\nNumber of u's %d",u);
printf("\nNumber of letterss %d",total);
}
Posted by
BADTNC
at
1:00 PM
0
comments
Labels: C Programming
Find the Maximum value in a Array
#include
void main()
{
int i,count=0,max,x;
int str[10];
for(i=0;i<3;i++)
{
printf("enter:");
scanf("%d",&str[i]);
}
max=str[0];
for(x=0;x<3;x++)
{
if(max < str[x] )
max=str[x];
}
printf("Vaval is:%d",max);
}
Posted by
BADTNC
at
11:50 AM
0
comments
Labels: C Programming
Finding the Vowels Count in a Word
#include
void main()
{
int i,count=0;
char str[9];
printf("Enter a Word : ");
gets(str);
for(i=1;i<8;i++)
{
if('a'==str[i]||'e'==str[i]||'i'==str[i]||'o'==str[i]||'u'==str[i])
count++;
}
printf("Vaval count is:%d",count);
}
Posted by
BADTNC
at
11:48 AM
0
comments
Labels: C Programming
Riverse String abc <---- cba (My Method)
#include
void main()
{
int i,x;
char str[10],rev[10];
for(i=0;i<3;i++)
{
printf("enter:");
fflush(stdin);
scanf("%c",&str[i]);
}
for(x=3;x>=0;x--)
printf("%c",str[x]);
}
Posted by
BADTNC
at
11:47 AM
0
comments
Labels: C Programming
STAR PATTERNS
...:::STAR PATTERNS:::...
*
**
***
****
*****
******
*******
********
*********
#include
void main()
{
int row,col;
for(row=1;row<=10;row++)
{
for(col=1;col<=row;col++)
{
printf("*");
}
printf("\n");
}
}
------------------------------------------------------------------------------------------
*********
********
*******
******
*****
****
***
**
*
#include
void main()
{
int row,col;
for(row=10;row>=0;row--)
{
for(col=1;col<=row;col++)
{
printf("*");
}
printf("\n");
}
}
------------------------------------------------------------------------------------------
*
**
***
****
*****
******
*******
********
*********
#include
void main()
{
int row,col;
for(row=1;row<=10;row++)
{
for(col=10;col>=row;col-=1)
{
printf(" ");
}
for(col=1;col<=row;col++)
{
printf("*");
}
printf("\n");
}
}
------------------------------------------------------------------------------------------
*********
********
*******
******
*****
****
***
**
*
#include
void main()
{
int row,col;
for(row=10;row>=0;row--)
{
for(col=10;col>=row;col-=1)
{
printf(" ");
}
for(col=1;col<=row;col++)
{
printf("*");
}
printf("\n");
}
}
------------------------------------------------------------------------------------------
*
***
*****
*******
*********
*******
*****
***
*
#include
void main()
{
int row,col;
for(row=1;row<=10;row++)
{
for(col=10;col>=row;col-=2)
{
printf(" ");
}
for(col=1;col<=row;col++)
{
printf("*");
}
printf("\n");
}
for(row=10;row>=0;row--)
{
for(col=10;col>=row;col-=2)
{
printf(" ");
}
for(col=1;col<=row;col++)
{
printf("*");
}
printf("\n");
}
}
Posted by
BADTNC
at
9:37 AM
0
comments
Labels: C Programming
Mr.Gamidu's Model Paper Answers ( In course test)
Question 1.C.
# include
void main()
{
int intvalue;
char charval;
printf("Enter the value and the character:");
scanf("%d",&intvalue);
scanf("%c",&charval);
printf("the values are %d,%c",intvalue,charval);
}
-----------------------------------------------------------------------------------------------
Question 1.E.
#include
void main()
{
int x;
for(x=999;x>=1;x-=2)
printf("\n%d",x);
}
-----------------------------------------------------------------------------------------------
Question 1.F.
#include
void main()
{
int count=0;
do
{
if(count%2==0)
printf("\n%d",count);
count+=2;
}
while(count<100);
}
-----------------------------------------------------------------------------------------------
Question 1.G.
#include
void main()
{
int total,x;
for(x=100;x<=150;x++)
total=total+x;
printf("%d",total);
}
..::2nd method::..
#include
void main()
{
int count,x=0;
do
{
if(x<=150 && x>=100)
count+=x;
}
while(x=x+1);
printf("\n%d",count);
}
********************************************************************
Question 4.6.a.
#include
void main()
{
int x=0;
for(x=2;x<=13;x+=2)
printf("\n%d",x);
}
-----------------------------------------------------------------------------------------------
Question 4.6.b.
#include
void main()
{
int x=0;
for(x=5;x<=22;x+=7)
printf("\n%d",x);
}
-----------------------------------------------------------------------------------------------
Question 4.6.c.
#include
void main()
{
int x=0;
for(x=3;x<=15;x+=3)
printf("\n%d",x);
-----------------------------------------------------------------------------------------------
Question 4.6.d.
#include
void main()
{
int x=0;
for(x=1;x<=5;x+=7)
printf("\n%d",x);
}
-----------------------------------------------------------------------------------------------
Question 4.6.e.
# include
void main()
{
int x;
for(x=12; x>=2; x-=3)
printf("\n%d",x);
}
********************************************************************
Question 4.7.a.
#include
void main()
{
int x;
for(x=1;x<=7;x++)
printf("\n%d",x);
}
-----------------------------------------------------------------------------------------------
Question 4.7.b.
#include
void main()
{
int x;
for(x=3;x<=23;x+=5)
printf("\n%d",x);
}
-----------------------------------------------------------------------------------------------
Question 4.7.c.
#include
void main()
{
int x;
for(x=20;x>=-10;x-=6)
printf("\n%d",x);
}
-----------------------------------------------------------------------------------------------
Question 4.7.d.
#include
void main()
{
int x;
for(x=19;x<=51;x+=8)
printf("\n%d",x);
}
********************************************************************
Question 4.8.
#include
void main()
{
int x;
int y;
int i;
int j;
printf("Enter the colloums and rows 1-20:");
scanf("%d %d",&x,&y);
for(i=1; i<=y ; i++)
{
for(j=1;j<=x;j++)
{
printf("@");
}
printf("\n");
}
}
********************************************************************
Question 4.9.
#include
void main()
{
int value=0,total=0,i=0,num=0;
printf("How many Numbers you should want to Sum:");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
printf("Enter the Value %d :",i);
scanf("%d",&value);
total=total+value;
}
printf("Total is : %d",total);
}
********************************************************************
Question 4.11.
#include
void main()
{
int i,how,value,min;
printf("Enter How manu numbers you want to add: ");
scanf("%d",&how);
for(i=1;i<=how;i++)
{
printf("Enter the value %d :",i);
scanf("%d",&value);
if(min>value)
{
min=value;
}
}
printf("value is :%d",min);
}
********************************************************************
Question 4.12.
#include
void main()
{
int i,total=0;
for(i=2;i<=30;i+=2)
{
total=total+i;
}
printf("Total of is: %d",total);
}
********************************************************************
Question 4.13.
#include
void main()
{
int i,total;
for(i=1;i<=15;i+=2)
{
total=total*i;
}
printf("Total of is: %d",total);
}
********************************************************************
Question 4.14.
#include
void main()
{
int i,num,fact=1;
printf("give the Limit: ");
scanf("%d",&num);
for(i=1;i<=num;i++)
fact=fact*i;
printf("%d",fact);
}
********************************************************************
Question 4.16.a.
#include
void main()
{
int row,col;
for(row=1;row<=10;row++)
{
for(col=1;col<=row;col++)
{
printf("*");
}
printf("\n");
}
}
-----------------------------------------------------------------------------------------------
Question 4.16.b
#include
void main()
{
int row,col;
for(row=10;row>=0;row--)
{
for(col=1;col<=row;col++)
{
printf("*");
}
printf("\n");
}
}
********************************************************************
Question 4.17.
#include
void main()
{
int accn,cl,bl;
float new;
printf("Enter the Account Number: ");
scanf("%d",&accn);
printf("Enter the Current Balance: ");
scanf("%d",&cl);
printf("Enter the Enter the Credit Limit: ");
scanf("%d",&bl);
new=bl/2;
if(new
else
printf("you cant do the transaction");
}
********************************************************************
Question 4.18.
#include
void main()
{
int num,i,x;
for(i=0;i<5;i++)
{
printf("\nEnter the number %d :",i+1);
scanf("%d",&num);
for(x=1;x<=num;x++)
printf("*",x);
}
}
********************************************************************
Question 4.19.
#include
void main()
{
int num;
float pro,total;
printf("Enter the product type:" );
scanf("%d",&num);
switch (num)
{
case 1:
printf("Enter the Quantity:" );
scanf("%f",&pro);
total=pro*2.98;
printf("Total is:%.2f",total);break;
case 2:
printf("Enter the Quantity:" );
scanf("%f",&pro);
total=pro*4.50;
printf("Total is:%.2f",total);break;
case 3:
printf("Enter the Quantity:" );
scanf("%f",&pro);
total=pro*9.98;
printf("Total is:%.2f",total);break;
case 4:
printf("Enter the Quantity:" );
scanf("%f",&pro);
total=pro*4.49;
printf("Total is:%.2f",total);break;
case 5:
printf("Enter the Quantity:" );
scanf("%f",&pro);
total=pro*6.87;
printf("Total is:%.2f",total);break;
}
}
********************************************************************
Question 4.31.
#include
void main()
{
int row,col;
for(row=1;row<=10;row++)
{
for(col=10;col>=row;col-=2)
{
printf(" ");
}
for(col=1;col<=row;col++)
{
printf("*");
}
printf("\n");
}
for(row=10;row>=0;row--)
{
for(col=10;col>=row;col-=2)
{
printf(" ");
}
for(col=1;col<=row;col++)
{
printf("*");
}
printf("\n");
}
}
********************************************************************
Posted by
BADTNC
at
9:02 AM
2
comments
Labels: C Programming
