-
Notifications
You must be signed in to change notification settings - Fork 772
Create armstrong.c #1311
base: main
Are you sure you want to change the base?
Create armstrong.c #1311
Conversation
Thanks for opening this pull request! Please check out our contributing guidelines. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These modifications aim to provide more clarity to the user about what each output message represents. Feel free to adjust the messages further based on your specific preferences or requirements.
algorithms/C/maths/armstrong.c
Outdated
temp/=10; // we extract a digit from number using (temp%10) then | ||
} // raise that digit to number of digits in the number using pow function | ||
// (pow()+0.5) is used to increase precision | ||
printf("%d\n",sum); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
must be more clear , printf("Sum of powered digits: %d\n", sum);
algorithms/C/maths/armstrong.c
Outdated
digit++; //counting number of digits in the input number | ||
temp=temp/10; | ||
} | ||
printf("%d\n",digit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must be more clear printf("Number of digits: %d\n", digit);
printf("Not Armstrong"); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to return something, if your return type is int. return 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added return 0;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more clarity in print statements.
Okay
…On Thu, 18 Jan 2024, 2:52 am MdialloC19, ***@***.***> wrote:
***@***.**** requested changes on this pull request.
These modifications aim to provide more clarity to the user about what
each output message represents. Feel free to adjust the messages further
based on your specific preferences or requirements.
------------------------------
In algorithms/C/maths/armstrong.c
<#1311 (comment)>
:
> + int num,digit=0,temp,sum=0; //define variables
+ printf("enter the number: ");
+ scanf("%d",&num); //taking inputs
+ temp=num;
+ while(temp>0){
+ digit++; //counting number of digits in the input number
+ temp=temp/10;
+ }
+ printf("%d\n",digit);
+ temp=num;
+ while(temp>0){
+ sum=sum+ (int)(pow(temp%10, digit)+0.5); // checking the armstrong property of the number
+ temp/=10; // we extract a digit from number using (temp%10) then
+ } // raise that digit to number of digits in the number using pow function
+ // (pow()+0.5) is used to increase precision
+ printf("%d\n",sum);
must be more clear , printf("Sum of powered digits: %d\n", sum);
------------------------------
In algorithms/C/maths/armstrong.c
<#1311 (comment)>
:
> +// an armstrong number is a number that equals the sum of its digits, each raised to a power.
+// power is the number of digits in the number eg. 123 has three digits, so power will be 3.
+
+#include<stdio.h>
+#include<math.h>
+
+int main(){ //main function
+ int num,digit=0,temp,sum=0; //define variables
+ printf("enter the number: ");
+ scanf("%d",&num); //taking inputs
+ temp=num;
+ while(temp>0){
+ digit++; //counting number of digits in the input number
+ temp=temp/10;
+ }
+ printf("%d\n",digit);
Must be more clear printf("Number of digits: %d\n", digit);
------------------------------
In algorithms/C/maths/armstrong.c
<#1311 (comment)>
:
> + printf("%d\n",digit);
+ temp=num;
+ while(temp>0){
+ sum=sum+ (int)(pow(temp%10, digit)+0.5); // checking the armstrong property of the number
+ temp/=10; // we extract a digit from number using (temp%10) then
+ } // raise that digit to number of digits in the number using pow function
+ // (pow()+0.5) is used to increase precision
+ printf("%d\n",sum);
+ if(num==sum){ //checking if the new number is equal to the input number
+ printf("Armstrong");
+ }
+ else{
+ printf("Not Armstrong");
+ }
+}
+
You have to return something, if you return type of the main is int. return
0
—
Reply to this email directly, view it on GitHub
<#1311 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A65ND5MB7HPSFQKVUQESNL3YPA6HVAVCNFSM6AAAAABB224S5OVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTQMRYGIYDCNZRHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything ok !!!!
PR Checklist:
What kind of change does this PR introduce? (check at least one)
Briefly describe the changes in this PR
This is algorithm is to find if a given number is Armstrong number or not. C language is used to implement it in this program.
Other information: