Sei sulla pagina 1di 26

C-Programming 1

Assignment No- .

Name of the student : ______________________________________

Class BCA

Sem : 1

ERPID :__________________________________________________

Date of submission : _______________________________________

Marks obtained (out of 10 )_________________________________

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();

printf("\nEnter marks in five subjects");

printf("\n\nEnter marks in subject 1: ");

scanf(" %f",&m1);

printf("\nEnter marks in subject 2: ");

scanf(" %f",&m2);

printf("\nEnter marks in sunject 3: ");

scanf(" %f",&m3);

printf("\nEnter marks in subject 4: ");

scanf(" %f",&m4);

printf("\nEnter marks in subject 5: ");

scanf(" %f",&m5);

p=(m1+m2+m3+m4+m5)/5;

printf("\nDivision according to the percentage: ");

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();

printf("\nEnter the number of units consumed: ");

scanf(" %f",&unit);

if(unit<=100)

charges=unit*0.40;

else if(unit>100 && unit<=300)

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");

printf("\n\n\n\nYour net consumption charges= %f",tcharge);

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();

printf("\nEnter the number ");

scanf(" %d",&n);

for(i=2;i<n/2;i++)

if(n%i==0)

f=1;

if(f==1)

printf("The entered number is not a Prime number");

else

printf("The entered number is a Prime number");

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();

printf("\nEnter the number ");

scanf(" %d",&n);

while(n>0)

r=n%10;

n=n/10;

if(r%2==0)

even+=r;

else

odd+=r;

printf("\nThe number entered by you contains sum of");

printf("\nEven digits: %d",even);

printf("\nOdd digits: %d",odd);

getch();

C - Programming CES - 1
}

Output : 4

C - Programming CES - 1
Sol. 5

#include<stdio.h>

#include<conio.h>

void main()

intn,i;

clrscr();

printf("Enter the number whose divisors is to calculated ");

scanf(" %d",&n);

for(i=1;i<=n/2;i++)

if(n%i==0)

printf("\nThe divisors are: %d",i);

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();

printf("\nEnter 2 numbers whose LCM and GCD is to be calculated: ");

scanf(" %d %d",&n1,&n2);

for(i=1;i<=n1 &&i<=n2;i++)

if(n1%i==0 && n2%i==0)

gcd=i;

lcm=(n1*n2)/gcd;

printf("\n\nLCM of the numbers %d and %d is %d\nGCD of the numbers %d


and %d is %d",n1,n2,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();

printf("Enter the name: ");

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();

printf("Enter the name: ");

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();

printf("\nEnter the string ");

scanf(" %s",str);

for(i=0;str[i]!='\0';i++)

if(str[i]==' ')

space++;

if(str[i]=='\t')

tab++;

if(str[i]=='\n')

line++;

printf("\nTotal number of spaces: %d",space);

printf("\nTotal number oftabs: %d",tab);

printf("\nTotal number of lines: %d",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();

printf("\nEnter the string ");

scanf(" %s",str);

printf("\nEnter the character ");

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]);

printf("\nNew string %s",str);

getch();

C - Programming CES - 1
Output : 10

C - Programming CES - 1

Potrebbero piacerti anche