You are on page 1of 3

IF STATEMENT-SIMPLE IF ELSE STATEMENT: SIMPLE FOR LOOP:

#include<stdio.h> #include<stdio.h> (A)


void main() void main() #include<stdio.h>
{ { void main()
int number=0; int number=0; {
printf("Enter a number:"); printf("enter a number:"); int i=0;
scanf("%d",&number); scanf("%d",&number); for(i=1;i<=10;i++)
if(number%2==0) if(number%2==0) {
{ { printf("%d \n",i);
printf("%d is even number",number); printf("%d is even number",number); }
} } getch();
getch(); else }
} {
printf("%d is odd number",number); (B)
NESTED IF STATEMENT: } #include<stdio.h>
getch(); #include<stdlib.h>
#include <stdio.h> } int main(){
void main() int i,j,k,l,n;
{ ELSE IF LADDER: system("cls");
int a, b, c; printf("enter the range=");
printf("Enter three numbers?"); #include <stdio.h> scanf("%d",&n);
scanf("%d %d %d",&a,&b,&c); void main() for(i=1;i<=n;i++)
if(a>b && a>c) { {
{ int marks; for(j=1;j<=n-i;j++)
printf("%d is largest",a); printf("Enter your marks?"); {
} scanf("%d",&marks); printf(" ");
if(b>a && b > c) if(marks > 85 && marks <= 100) }
{ { for(k=1;k<=i;k++)
printf("%d is largest",b); printf("Congrats ! you scored grade A ..."); {
} } printf("%d",k);
if(c>a && c>b) else if (marks > 60 && marks <= 85) }
{ { for(l=i-1;l>=1;l--)
printf("%d is largest",c); printf("You scored grade B + ..."); {
} } printf("%d",l);
if(a == b && a == c) else if (marks > 40 && marks <= 60) }
{ { printf("\n");
printf("All are equal"); printf("You scored grade B ..."); }
} } return 0;
getch(); else if (marks > 30 && marks <= 40) }
} {
printf("You scored grade C ...");
}
else
{
printf("Sorry you are fail ...");
}}
WHILE LOOP: SWITCH CASE: (B)
#include <stdio.h>
(A) (A) int main()
#include<stdio.h> #include <stdio.h> {
void main() int main() char ch;
{ { printf("Enter any alphabet: ");
int i=1,n,m,a; int day = 2; scanf("%c", &ch);
printf("\nEnter the limit:"); printf("The day with number %d is ", day); switch(ch)
scanf("%d",&n); switch (day) { {
printf("\nEnter the table's number:"); case 1: case 'a':
scanf("%d",&a); printf("Monday"); printf("Vowel");
while(i<=n) break; break;
{ case 2: case 'e':
printf("\n%d*%d=%d",i,a,i*a); printf("Tuesday"); printf("Vowel");
i++; break; break;
} case 3: case 'i':
getch(); printf("Wednesday"); printf("Vowel");
} break; break;
case 4: case 'o':
DO WHILE LOOP: printf("Thursday"); printf("Vowel");
break; break;
(A) #include <stdio.h> case 5: case 'u':
void main() printf("Friday"); printf("Vowel");
{ break; break;
int i = 0; case 6: case 'A':
do { printf("Saturday"); printf("Vowel");
printf("Geeks\n"); break; break;
i++; case 7: case 'E':
} while (i < 3); printf("Sunday"); printf("Vowel");
getch(); break; break;
} default: case 'I':
printf("Invalid Input"); printf("Vowel");
(B) break; break;
#include <stdio.h> } case 'O':
void main() return 0; printf("Vowel");
{ } break;
bool condition = false; case 'U':
do { printf("Vowel");
printf("This is loop body."); break;
} while (condition); default:
getch(); printf("Consonant");
} }
return 0;
}
ARRAYS:

(A)

#include<stdio.h>
int main(){
int i=0;
int marks[5]={20,30,40,50,60};
for(i=0;i<5;i++){
printf("%d \n",marks[i]);
}
return 0;
}

(B)
#include<stdio.h>
void main ()
{
int i, j,temp;
int a[10] = { 10, 9, 7, 101, 23, 44, 12, 78, 34, 23};
for(i = 0; i<10; i++)
{
for(j = i+1; j<10; j++)
{
if(a[j] > a[i])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
printf("Printing Sorted Element List ...\n");
for(i = 0; i<10; i++)
{
printf("%d\n",a[i]);
}
}

You might also like