C Style Find The Largest Number Among Three Numbers and Calculate The Sum of Natural Numbers
C Style Find The Largest Number Among Three Numbers and Calculate The Sum of Natural Numbers
// Using if Statement
#include <stdio.h>
int main() {
return 0;
}
#include <stdio.h>
int main() {
return 0;
}
#include <stdio.h>
int main() {
double n1, n2, n3;
// outer if statement
if (n1 >= n2) {
// inner if...else
if (n1 >= n3)
printf("%.2lf is the largest number.", n1);
else
printf("%.2lf is the largest number.", n3);
}
// inner if...else
if (n2 >= n3)
printf("%.2lf is the largest number.", n2);
else
printf("%.2lf is the largest number.", n3);
}
return 0;
}
#include <stdio.h>
int main() {
int n, i, sum = 0;
#include <stdio.h>
int main() {
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
i = 1;
while (i <= n) {
sum += i;
++i;
}
printf("Sum = %d", sum);
return 0;
}
#include <stdio.h>
int main() {
int n, i, sum = 0;
do {
printf("Enter a positive integer: ");
scanf("%d", &n);
} while (n <= 0);