C - Programming Ces - 1
C - Programming Ces - 1
C - Programming Ces - 1
Assignment No- .
Class BCA
Sem : 1
ERPID :__________________________________________________
Signature of Faculty_______________________________________
C - Programming CES - 1
Assignment 1
Questions
Question 1: WAP to input marks in five subjects of a student and calculate the division
according to the following conditions:
Percentage Division
>=60 First
50-59 Second
40-49 Third
<40 Fail
Question 2: An electricity board charges according to the following rates:
For the first 100 units 40 paisa per unit.
For the first 200 units 50 paisa per unit.
Beyond 300 units 60 paisa per unit.
All users are charged meter charges also, which are Rs. 50/-
Question 3: WAP to check that given number is prime or not.
Question 4: WAP to input a number and count its even and odd digits out their sum
separately.
Question 5: WAP to generate divisors of an integer.
Question 6: WAP to find out the LCM and GCD of two given numbers.
Question 7: WAP to input a name and print the name in the following pattern
R RAJAT
RA RAJA
RAJ RAJ
RAJA RA
RAJAT R
Question 8: WAP to print the following series:
1 1
12 22
123 333
1234 4444
Question 9: WAP to count the number of spaces, tabs and new line characters in a given
string.
Question 10: WAP to input a character and a string. Each occurrence of a character in the
string should be converted to opposite case i.e. upper to lower case or vice versa.
C - Programming CES - 1
Solutions
Sol. 1
#include<stdio.h>
#include<conio.h>
void main()
float m1,m2,m3,m4,m5,p;
clrscr();
scanf(" %f",&m1);
scanf(" %f",&m2);
scanf(" %f",&m3);
scanf(" %f",&m4);
scanf(" %f",&m5);
p=(m1+m2+m3+m4+m5)/5;
if(p>=60)
printf("First Division");
else if(p>=50)
C - Programming CES - 1
printf("Second Division");
else if(p>=40)
printf("Third Division");
else
printf("Fail");
getch();
Output :1
C - Programming CES - 1
Sol. 2
#include<stdio.h>
#include<conio.h>
void main()
floatunit,charges,tcharge;
clrscr();
scanf(" %f",&unit);
if(unit<=100)
charges=unit*0.40;
charges=40+(unit-100)*0.50;
else
charges=140+(unit-300)*0.60;
tcharge=50+charges;
printf("\n\nCharges for unit are as follows\n\nFor the first 100 units - 40 paisa
per unit\nFor the next 200 uits - 50 paisa er unit\nBeyond 300 units - 60 paisa
per unit\n\nNet consumption charges= Meter charges(Rs. 50) + Consumption
Charges");
getch();
C - Programming CES - 1
Output : 2
C - Programming CES - 1
Sol. 3
#include<stdio.h>
#include<conio.h>
void main()
intn,i,f=0;
clrscr();
scanf(" %d",&n);
for(i=2;i<n/2;i++)
if(n%i==0)
f=1;
if(f==1)
else
getch();
C - Programming CES - 1
}
Output : 3
C - Programming CES - 1
Sol. 4
#include<stdio.h>
#include<conio.h>
void main()
intn,r,odd=0,even=0;
clrscr();
scanf(" %d",&n);
while(n>0)
r=n%10;
n=n/10;
if(r%2==0)
even+=r;
else
odd+=r;
getch();
C - Programming CES - 1
}
Output : 4
C - Programming CES - 1
Sol. 5
#include<stdio.h>
#include<conio.h>
void main()
intn,i;
clrscr();
scanf(" %d",&n);
for(i=1;i<=n/2;i++)
if(n%i==0)
getch();
C - Programming CES - 1
Output : 5
C - Programming CES - 1
Sol . 6
#include<stdio.h>
#include<conio.h>
void main()
int n1,n2,i,lcm,gcd;
clrscr();
scanf(" %d %d",&n1,&n2);
for(i=1;i<=n1 &&i<=n2;i++)
gcd=i;
lcm=(n1*n2)/gcd;
getch();
C - Programming CES - 1
Output : 6
C - Programming CES - 1
Sol. 7(a)
#include<stdio.h>
#include<conio.h>
void main()
inti,j;
char name[20];
clrscr();
scanf(" %s",name);
for(i=0;name[i]!='\0';i++)
for(j=0;j<=i;j++)
printf("%c",name[j]);
printf("\n");
getch();
C - Programming CES - 1
Output : 7(a)
C - Programming CES - 1
Sol. 7(b)
#include<stdio.h>
#include<conio.h>
void main()
inti,j,n;
char name[20];
clrscr();
scanf(" %s",name);
for(i=0;name[i]!='\0';i++);
n=i;
for(i=n;name[i]>=0;i--)
for(j=0;j<=i;j++)
printf("%c",name[j]);
printf("\n");
getch();
C - Programming CES - 1
Output : 7(b)
C - Programming CES - 1
Sol . 8(a)
#include<stdio.h>
#include<conio.h>
void main()
inti,j;
clrscr();
for(i=1;i<5;i++)
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
getch();
C - Programming CES - 1
Output : 8(a)
C - Programming CES - 1
Sol . 8(b)
#include<stdio.h>
#include<conio.h>
void main()
inti,j;
clrscr();
for(i=1;i<5;i++)
for(j=0;j<i;j++)
printf("%d",i);
printf("\n");
getch();
C - Programming CES - 1
Output : 8(b)
C - Programming CES - 1
Sol. 9
#include<stdio.h>
#include<conio.h>
void main()
inti,space,tab,line;
charstr[100];
space=tab=line=0;
clrscr();
scanf(" %s",str);
for(i=0;str[i]!='\0';i++)
if(str[i]==' ')
space++;
if(str[i]=='\t')
tab++;
if(str[i]=='\n')
line++;
C - Programming CES - 1
getch();
Output : 9
C - Programming CES - 1
Sol. 10
#include<stdio.h>
#include<conio.h>
void main()
inti;
charch,str[20];
clrscr();
scanf(" %s",str);
scanf(" %c",&ch);
for(i=0;str[i]!='\0';i++)
if(str[i]==ch)
if(islower(str[i]))
str[i]=toupper(str[i]);
else
str[i]=tolower(str[i]);
getch();
C - Programming CES - 1
Output : 10
C - Programming CES - 1