[go: up one dir, main page]

0% found this document useful (0 votes)
15 views5 pages

FCP Assignment 3

The document contains various C and C++ programming assignments focusing on different tasks such as counting digits in a number, calculating tax based on salary, finding minimum and maximum values from a set of numbers, comparing dates, and converting two-digit numbers to words. Each section includes code snippets that demonstrate the implementation of these tasks. The assignments aim to enhance programming skills through practical coding exercises.

Uploaded by

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

FCP Assignment 3

The document contains various C and C++ programming assignments focusing on different tasks such as counting digits in a number, calculating tax based on salary, finding minimum and maximum values from a set of numbers, comparing dates, and converting two-digit numbers to words. Each section includes code snippets that demonstrate the implementation of these tasks. The assignments aim to enhance programming skills through practical coding exercises.

Uploaded by

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

FCP Assignment 3

Anurag Bhunia

Chapter 5

Q1.
#include <stdio.h>
int main(){
int n,i=0;
printf("Enter the number:");
scanf("%d",&n);
if(n==0){
printf("The number has 1 digit.");
}
else{
while(n>0){
i++;
n/=10;
}
}
if(i==1){
printf("The number has 1 digit.");
}
else{
printf("The number has %d digits.",i);
}
}

Q5.
#include <stdio.h>
int main(){
float s;
printf("Enter your salary:");
scanf("%f",&s);
if(s<=750){
printf("Your tax due is $ %f",0.01*s);
}
else if(s>750 && s<=2250){
printf("Your tax due is $ %f",7.5+(s-750)*0.02);
}
else if(s>2250 && s<=3750){
printf("Your tax due is $ %f",37.5+(s-2250)*0.03);
}
else if(s>3750 && s<=5250){
printf("Your tax due is $ %f",82.5+(s-3750)*0.04);
}
else if(s>5250 && s<=7000){
printf("Your tax due is $ %f",142.5+(s-5250)*0.05);
}
else{
printf("Your tax due is $ %f",230+(s-7000)*0.06);
}
}

Q7.
#include <iostream>
int main(){
int n1,n2,n3,n4;
printf("Enter the four numbers:");
scanf("%d %d %d %d",&n1,&n2,&n3,&n4);
int arr[4]={n1,n2,n3,n4};
int min=n1,max=n1;
for(int i=1;i<4;i++){
if(arr[i]>max){
max=arr[i];
}
if(arr[i]<min){
min=arr[i];
}
}
printf("The mimimum is %d and the maximum is %d",min,max);
}

Q9.
#include <iostream>
int main(){
int d1,m1,y1,d2,m2,y2;
printf("Enter the first date:");
scanf("%d/%d/%d",&d1,&m1,&y1);
printf("Enter the second date:");
scanf("%d/%d/%d",&d2,&m2,&y2);
if(y2<y1){
printf("The second date comes earlier.");
}
else if(y2>y1){
printf("The first date comes earlier.");
}
else{
if(m2<m1){
printf("The second date comes earlier.");
}
else if(m2>m1){
printf("The first date comes earlier.");
}
else{
if(d1<d2){
printf("The first date comes earlier.");
}
else if(d1>d2){
printf("The second date comes earlier.");
}
else{
printf("Both dates are the same.");
}
}
}
}

Q11.
#include <iostream>
void units(int n){
if(n==0){
printf("");
}
else if(n==1){
printf("One");
}
else if(n==2){
printf("Two");
}
else if(n==3){
printf("Three");
}
else if(n==4){
printf("Four");
}
else if(n==5){
printf("Five");
}
else if(n==6){
printf("Six");
}
else if(n==7){
printf("Seven");
}
else if(n==8){
printf("Eight");
}
else{
printf("Nine");
}
}
int main(){
printf("Enter the two digit number:");
int n;
scanf("%d",&n);
if(n/10==1){
if(n==10){
printf("Ten");
}
else if(n==11){
printf("Eleven");
}
else if(n==12){
printf("Twelve");
}
else if(n==13){
printf("Thirteen");
}
else if(n==14){
printf("Fourteen");
}
else if(n==15){
printf("Fifteen");
}
else if(n==16){
printf("Sixteen");
}
else if(n==17){
printf("Seventeen");
}
else if(n==18){
printf("Eighteen");
}
else{
printf("Nineteen");
}
}
else if(n/10==2){
printf("Twenty ");
units(n-(n/10)*10);
}
else if(n/10==3){
printf("Thirty ");
units(n-(n/10)*10);
}
else if(n/10==4){
printf("Forty ");
units(n-(n/10)*10);
}
else if(n/10==5){
printf("Fifty ");
units(n-(n/10)*10);
}
else if(n/10==6){
printf("Sixty ");
units(n-(n/10)*10);
}
else if(n/10==7){
printf("Seventy ");
units(n-(n/10)*10);
}
else if(n/10==8){
printf("Eighty ");
units(n-(n/10)*10);
}
else{
printf("Ninety ");
units(n-(n/10)*10);
}
}

You might also like