Write a program to add of number in c programming. The output of the program should be like the figure below:
Enter an integer
98
Sum of digits of entered number = 17
Enter an integer
98
Sum of digits of entered number = 17
#include<stdio.h> Int main ( ) { Int a,b; /*variable declaration*/ Printf(“insert your integer number \n”); /*insert the integer number that is 98*/ Scanf(“%d”,&a); /* the input percent d,mpersand sign and variablename */ Int y=17; /*assigning the variable value that is yis equal to 17*/
While(y<=17); /*y is is less then or equal to 17*/
{
Printf(“the sum is %d\n”,y); /*display the output of sum y*/
}
Return 0; /*returning*/
}
introduction loop structure
loop is know as a group of instruction be executed repeatedly, until a logical condition has been satisfied. looping statements are used to control program flow. There are three major loop statements in the C programming language.
3 major loop : * for loop * while loop * do…while loop
For loop.
For loop is the fundamental looping statement in C. It is often used for situations in which you want to execute a specific task number of times.
While loop
In the while loop, the body of the loop is executed as long as the expression is true. And when the expression become false, program control passes to the line that follows the loop.
Do.. while loop
This loop structure is similar to the while loop. The do while loop checks its condition at the end of the loop. This means that the do while loop will always excute atleast once.
SPG0412
NAME:NURUL EKA SHAHFIKA BINTI RAZI
ID:PIC127060
MISS:MISS NURUL RADFIZA BINTI MUHAMAD RASHID