0% found this document useful (0 votes)
16 views8 pages

C First Assignment Comp

it is a detail code of c with the series of solved c quesiton

Uploaded by

novaluna1913
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

C First Assignment Comp

it is a detail code of c with the series of solved c quesiton

Uploaded by

novaluna1913
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

To find the price of n mangoes given the price of a dozen mangoes


Ans:
#include<stdio.h>
main(){
double dozen_mango, total, each_mango;
int num;
printf("enter the price of dozen mango:");
scanf("%lf",&dozen_mango);
each_mango=dozen_mango/12;
printf("enter the number of mango:");
scanf("%d",&num);
total=each_mango*num;
printf("the price of %d mangoes is %.2lf",num,total );
}

2. To input any 4-digit number and find the sum of first and last numbers
Ans:
#include<stdio.h>
main(){
int number,num1,num4,sum;
printf("Enter 4-digit number:");
scanf("%d",&number);
num4=number%10;
num1=number/1000;
sum=num1+num4;
printf("the sum of first and last number of four digit number is %d",sum);
}
3. To input the marks of five subjects and calculate the percentage and give the grade as below:
>= 80 distinction, >=65 first division, >=50 second division >= 40 pass, < 40 fail

Ans:
#include<stdio.h>
main(){
double m1,m2,m3,m4,m5,total;
double percent;
printf(" enter the marks in between 0 to 100");
printf("enter the marks of five subject:");
scanf("%lf %lf %lf %lf %lf",&m1,&m2,&m3,&m4,&m5);
total=m1+m2+m3+m4+m5;
percent=(total/500)*100;
if(percent>=80 && percent<=100){
printf("You obtained %.2lf you got distinction", percent);
}
else if(percent>=65 && percent<80){
printf("You obtained %.2lf you got first division",percent);
}
else if(percent>=50 && percent<65){
printf("You obtained %.2lf you got second division", percent);
}
else if(percent>=40 && percent<50){
printf("You obtained %.2lf you got pass division" ,percent);
}
else{
printf("You obtained %.2lf you have failed.", percent);
}

4. To determine whether the given number is odd or even


Ans:
#include<stdio.h>
main(){
int num,odd,even;
printf("enter the number:");
scanf("%d",&num);
if(num%2==0){
printf("the %d is even",num);
}
else {
printf("the %d is odd",num);
}
}

5. NTC charges the following rate for local calls from a customer Calls charges

<=175 RS 200 >175 Rs 1 per extra call

Telecommunication Service Charge (TSC) = 10% of total charge

Vat = 13% of (total charge + TSC)

Find the amount paid by the customer, if the total number of calls is given by the user

Ans:

#include<stdio.h>

main(){

int num,charge,addtional_charge,extra_calls;

double TSC,Vat,Total_amount;

printf("enter the number of calls:");

scanf("%d",&num);

if(num<=175){

charge=200;
}

else {

extra_calls=num-175;

addtional_charge=extra_calls*1;

charge=200+addtional_charge;

TSC=0.1*charge;

Vat=0.13*(TSC+charge);

Total_amount=TSC+Vat+charge;

printf("the total amount paid by the user is %.2lf",Total_amount);

6. To find whether the given number is positive or not


Ans:
#include<stdio.h>
main(){
int num;
printf("enter the number:");
scanf("%d",&num);
if (num>0){
printf("the number %d is positive",num);
}
else if (num<0){
printf("the number %d is negative",num);
}else
{
printf("the number %d is netural",num);
}
}

7. To find the multiplication table of a given number


Ans:
#include<stdio.h>
main(){
int number, i,total;
printf("Enter the number:");
scanf("%d",&number);
printf("the multiplication table of the number is\n");
for(i=1;i<=10;++i){
total=number*i;
printf("%d*%d=%d\n",number,i,total);
}
}

8. To find the sum of digits from 1 to 100 which are exactly divisible by the given number
Ans:
#include<stdio.h>
main(){
int num,i,sum=0;
printf("enter the number:");
scanf("%d",&num);
for(i=1;i<=100;++i){
if(i%num==0){
sum=sum+i;
}
}
printf("The sum of digit from 1 to 100 which are exactly divisible by the given number is
%d",sum);
}

9. To input 3 digits number and find out whether the given number is Armstrong number or not.
E.g., 153 = (1*1*1) +(5*5*5) +(3*3*3)
Ans:
#include<stdio.h>
main(){
int num,rem,num1,sum=0;
printf("enter the number:");
scanf("%d",&num);
num1=num;
while(num!=0){
rem=num%10;
sum=sum+(rem*rem*rem);
num=num/10;
}
if (sum==num1){
printf("the number is armstrong number");
}
else{
printf("the number is not armstrong number");
}
}
10. To print the prime number between 1 to 100
Ans:
#include<stdio.h>
main(){
int i,j,count;
for(i=2;i<=100;++i){
count=0;
for(j=1;j<=100;++j){
if(i%j==0){
count++;
}
}
if(count<=2){
printf("%d\n",i);
}

}
11. To print the pattern given below

12

123

1234

12345

Ans:

#include<stdio.h>

main(){

int i,j;

for(i=1;i<=5;i++){

for(j=1;j<=i;j++){

printf("%d",j);

printf("\n");

You might also like