For Loop Best ☺️ Examples
Example1:
#include<stdio.h>
int main()
{
//i को 1 से तक दौड़ा के प्रिंट करवाइए
for(int i=1;i<=10;i++)
{
printf("%d\n",i);
}
}
//या,ये लिखें i को अलग से int में declare करके
#include<stdio.h>
int main()
{
int i=0;
for(i=1;i<=10;i++){
printf("%d \n",i);
}
return 0;
}
/*Output:-
1
2
3
4
5
6
7
8
9
10
[Process completed - press Enter]*/
Example2:
#include<stdio.h>
int main()
{
//no variable को int में declare करो
int no;
//जिसका table चाहिए,वो नंबर लिखो
printf("Enter any number\n");
scanf("%d",&no);
//For Loop के मदद से 1 से 10 तक i को दौड़ाइए
for(int i=1;i<=10;i++)
{
//i को 1 से 10 की no variable से बारी बारी से multiply ❌ करके प्रिंट करवाइए
printf("%d ",i*no);
}
}
/*Enter any number
11
11 22 33 44 55 66 77 88 99 110
[Process completed - press Enter]*/
Example3:
#include<stdio.h>
int main()
{
//no variable को declare कीजिए
int no;
//no variable में एक नंबर रखिए
printf("Enter any number\n");
//no variable को scanf के मदद से system को पढ़वाइए📑।
scanf("%d",&no);
//जिस नंबर तक प्रिंट करवाना हो,वो नंबर लिखिए
printf("Natural no from 1 to %d is given below\n",no);
//for Loop के मदद से i को 1 से लेकर no variable तक दौड़ाकर प्रिंट करवाइए
for(int i=1;i<=no;i++)
{
printf("%d ",i);
}
}
/*Enter any number
20
Natural no from 1 to 20 is given below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
[Process completed - press Enter]*/
Example4:
#include<stdio.h>
int main()
{
//ch को char data type में declare करके ch को a से z तक दौड़ा के प्रिंट करवाइए
for(char ch='a';ch<='z';ch++)
{
printf("%c ",ch);
}
}
/*a b c d e f g h i j k l m n o p q r s t u v w x y z
[Process completed - press Enter]*/
Example5:
#include<stdio.h>
int main()
{
//ch को char data type में declare करके ch को A से Z तक दौड़ा के प्रिंट करवाइए
for(char ch='A';ch<='Z';ch++)
{
printf("%c ",ch);
}
}
/*A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
[Process completed - press Enter]*/
Example6:
#include<stdio.h>
int main()
{
//ch को char data type में declare करके ch को 65 से 90 तक दौड़ा के प्रिंट करवाइए
for(char ch=65;ch<=90;ch++)
{
printf("%c ",ch);
}
}
/*A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
[Process completed - press Enter]*/
Example7:
#include<stdio.h>
int main()
{
//ch को char data type में declare करके ch को 97 से 122 तक दौड़ा के प्रिंट करवाइए
for(char ch=97;ch<=122;ch++)
{
printf("%c ",ch);
}
}
/*a b c d e f g h i j k l m n o p q r s t u v w x y z
[Process completed - press Enter]*/
Comments
Post a Comment