printf ("nested printf returned %d\n", printf ("inner printf\n"));
if (a > b && a > c) printf("%d\n", a); else if (b > c) printf("%d\n", b); else printf("%d\n", c);
we use "nested if" if we have to test a large number of possibilities and trials i an if statement.
// HI THIS IS MAYANK PATEL /*C Program to find Maximum of 3 nos. using Nested if*/ #include<stdio.h> #include<conio.h> void main() { int a,b,c; // clrscr(); printf("Enter three number\n\n"); scanf("d%d",&a,&b,&c); if(a>b) { if(a>c) { printf("\n a is maximum"); } else { printf("\n c is maximum"); } } else { if(b>c) { printf("\n b is maximum"); } else { printf("\n c is maximum"); } } getch(); }
switch is a loop which is used for checking various conditions and print corresponding matter.switch(a)//where a is that whose condition you have to check.#includemain(){char a;printf("enter a char.");scanf("%c",&a);switch(a){case 'a':printf("vowel");break;case 'e':printf("vowel");break;case 'i':printf("vowel");break;case 'o':printf("vowel");break;case 'u':printf("vowel");break;default:printf("consonent");}}
The solution is two use a nested for loop: int startingNum = 1; int maxNum = 10; for(int currentNum = startingNum; currentNum <= maxNum; currentNum++) { for(int j = 0; j < currentNum; j++) { printf("%d", currentNum); } printf("\n"); }
#include <stdio.h> int main() { int rows, star, spaces; int number_of_stars = 6; int number_of_rows = number_of_stars; for (rows=1; rows <= number_of_rows; rows++) { for (spaces=1; spaces <= number_of_stars; spaces++) { printf(" "); } for (star=1; star <= rows; star++) { printf("*"); printf(" "); } printf("\n"); number_of_stars = number_of_stars - 1; } return 0; }
Please ask clearly what you want to do with the image and explain why a nested for-loop is necessary.
you need nothing
No, it is a function. But printf does return a value: the number of characters it has written.
// leap year by @bhi// #include<stdio.h> #include<conio.h> void main() { int year; clrscr(); printf("Enter the Year that you want to check : "); scanf("%d", &year); if(year % 400 == 0) printf("%d is a Leap Year.", year); else if(year % 100 == 0) printf("%d is not a Leap Year.", year); else if(year % 4 == 0) printf("%d is a Leap Year.", year); else printf("%d is not a Leap Year", year); printf("\nPress any key to Quit..."); getch(); }
Nested loop, you mean; one loop in the other loop, eg: for (i=0; i<10; ++i) { for (j=0; j<i; ++j) { printf ("i=%d, j=%d\n", i, j); } }
You can use fputs() instead of printf().