You are on page 1of 8

Assignement No.

04

Name: abdul qadir

Class: 1 C

Reg: 098

Deadline : - The assignment is to be submitted (upload on portal) online till June 16, 2021. Viva
regarding assignment will be conducted after assignment deadline.

Problem 1: If a five-digit number is input through the keyboard, write a program to print
a new number by adding one to each of its digits. For example if the number that is input is
12391 then the output should be displayed as 23402.

Solution 1:

#include<stdio.h>

int main(){

int number, total, number_sum ,x, counter=0, num=1;

printf ("Enter some digits number : ");

scanf("%d",&number);

number_sum = number;

while(number_sum!=0){

number_sum=number_sum/10;

counter=counter+1;

}
for (x =1; x<counter; x++) {

num=num*10;

num=num+1;

total=number+num;

printf ("output: %d",total);

return 0;

Output: I put 45678 and enter

56789

Problem 2 : Write a program which takes an integer number (assume number is 3 digit) as
an input and shows that the entered number is Armstrong or not. If sum of cubes of each
digit of the number is equal to the number itself, then the number is called an Armstrong
number. For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 )

Solution 2:

#include <stdio.h>
void main(){

int num,r,sum=0,temp;

printf("Input a number: ");

scanf("%d",&num);

for(temp=num;num!=0;num=num/10){

r=num % 10;

sum=sum+(r*r*r);

if(sum==temp)

printf("%d is an Armstrong number.\n",temp);

else

printf("%d is not an Armstrong number.\n",temp);

Output: 153 enter

153 is an Armstrong number.


Problem 3: Write a program that takes obtained marks and total marks of each subject
from user (Assume three subjects). Your program should calculate the percentage marks
of the student.

Solution 3:

#include <stdio.h>

#include <string.h>

void main()

int rl,phy,che,ca,total;

float per;

char nm[20],div[10];

printf("Input the Roll Number of the student :");

scanf("%d",&rl);

printf("Input the Name of the Student :");

scanf("%s",nm);

printf("Input the marks of Physics, Chemistry and


Computer Application : ");
scanf("%d%d%d",&phy,&che,&ca);

total = phy+che+ca;

per = total/3.0;

if (per>=60)

strcpy(div,"First");

else

if (per<60&&per>=48)

strcpy(div,"Second");

else

if (per<48&&per>=36)

strcpy(div,"Pass");

else

strcpy(div,"Fail");

printf("\nRoll No : %d\nName of Student :


%s\n",rl,nm);
printf("Marks in Physics : %d\nMarks in Chemistry
: %d\nMarks in Computer Application :
%d\n",phy,che,ca);

printf("Total Marks = %d\nPercentage =


%5.2f\nDivision = %s\n",total,per,div);

Output: roll number 098 enter

Name qadir enter

Subjects marks 80 89 90 enter

Problem 4: Write a program converts a temperature from Celsius to Fahrenheit. Use the
following formula: F = 1.8 x C + 32 .

Solution:4
#include<stdio.h>
#include<conio.h>

int main () {

int celsius;
float fehrenteit;
printf (" Please enter celsius to convert
fehrenteit : ");
scanf("%d",&celsius);

fehrenteit = (float)1.8*celsius+32;
printf ("fehrenteit = %f ", fehrenteit);
getch ();
return 0;
}
Output: I give 50 celsious and enter
It gives 122,00000 ferenhite

Problem 5: Write a program that reads (inputs) three integers representing hours,
minutes, and seconds of a time. Then it calculates the equivalent time in seconds.

Solution : 5
#include<stdio.h>

int main (){

int hour, minutes, second, total;


printf ("Please enter hours : ");
scanf ("%d", &hour);

printf ("\n Please enter minutes: ");


scanf ("%d", &minutes);

printf (" \n Please enter seconds : ");


scanf ("%d", &second);

total=(hour*60*60) + (minutes*60) + second;


printf ("\n Total second is equal to : %d ",total);

return 0;
}
Input: I give 78 seconds enter
0:1:18

You might also like