0% found this document useful (0 votes)
8 views3 pages

Array Chap 05

The document provides examples of C programming concepts, including array declaration, loops, and functions. It includes code snippets demonstrating operations such as summing array elements, swapping variables, and string comparison using `strcmp()`. Additionally, it discusses the structure of the `main()` function and its importance in program execution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Array Chap 05

The document provides examples of C programming concepts, including array declaration, loops, and functions. It includes code snippets demonstrating operations such as summing array elements, swapping variables, and string comparison using `strcmp()`. Additionally, it discusses the structure of the `main()` function and its importance in program execution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Aa¨vq 05:

A¨v‡i: GKB ai‡bi GKvwaK WvUv wb‡q MwVZ we‡kl †WUv ÷ªvKPvi‡K A¨v‡i ejv nq|
A¨v‡i ˆZwi Kivi wmbU¨vK&ª/ wbqg:
data_type array_name[number of elements];
** A¨v‡ii cÖ_g Dcv`vb _v‡K 0- Zg N‡i, wØZxq Dcv`vb _v‡K 1- Zg N‡i Ges Zg Dcv`vb _v‡K (n-1) Zg N‡i|
** A¨v‡ii Dcv`vb¸‡jv †h N‡i _v‡K †m¸‡jv‡K A¨v‡ii Bb‡WK&ª ejv nq|
** A¨v‡ii Bb‡WK&ª 0 †_‡K ïiæ nq| ‡hgb- Bb‡WK&ª 0 †Z 87, Bb‡WK&ª 4 G 88 Av‡Q|

>> GKwU A¨v‡i‡Z 10wU msL¨v ivLv Av‡Q| msL¨v¸‡jvi †hvMdj wbY©‡qi wm †cÖvMÖvg wjL|
#include <stdio.h>
int main()
{
int numbers[10] = {5, 8, 12, 3, 7, 9, 4, 6, 10, 2};
int i, sum = 0;
for (i = 0; i < 10; i++)
{
sum = sum + numbers[i];
}
printf("%d\n", sum);
return 0;
}
** Mvi‡eR gvb: mvaviYZ GKwU f¨vwi‡qej †Nvlbv Kiv n‡j †mwU‡Z †Kvb gvb †`Iqv _v‡K bv| d‡j f¨vwi‡qejwU‡Z †h †Kvb
gvb _vK‡Z cv‡i| G‡K Mvi‡eR gvb ejv nq|
>> GKwU wm ‡cÖvMÖvg wjL †hb, a Gi gvb b †Z Ges b Gi gvb a ‡Z P‡j Av‡m| A_©vr `ywU ivwki gvb ci¯úi cwieZ©‡bi Rb¨
GKwU wm ‡cÖvMÖvg wjL|
#include <stdio.h>
int main()
{ Output
int a=10, b=9, c; a=9 b=10
c=a;
a=b;
b=c;
printf("a=%d b=%d", a, b);
return 0;
}
>> GKwU A¨v‡i‡Z 05wU msL¨v Av‡Q| msL¨v¸‡jvi µg D‡ë †`qvi Rb¨ GKwU wm ‡cÖvMÖvg wjL| †hgb: µg- 1 2 3 4 5
AvDUcyU- 5 4 3 2 1

#include <stdio.h>
int main() { Output
int numbers[5] = {10, 20, 30, 40, 50}; 50 40 30 20 10
for (int i = 4; i >= 0; i--)
{
printf("%d ", numbers[i]);
}
return 0;
}
** wm fvlvq K¨v‡i±vi UvB‡ci f¨vwi‡qe‡j GKwU Aÿi ivLv hvq| hw` GKvwaK Aÿi ivL‡Z nq, ZLb K¨v‡i±vi UvB‡ci A¨v‡i
e¨envi Kiv nq|
** w÷ªs: wm fvlvq GKvwaK Aÿi ivLvi Rb¨ †h A¨v‡i e¨envi Kiv nq Zv‡K w÷ªs ejv nq|
** wm †Z w÷ªs Gi Rb¨ c„_K †Kvb WvUv UvBc †bB|
>> wm †Z w÷ªs BbcyU MÖnY Ges AvDUcyU cÖ`v‡bi †cÖvMÖvg:
#include <stdio.h> Output
int main()
{ StringInputAndOutput
char name[80];
scanf("%s", name); StringInputAndOutput
printf("%s\n", name);
return 0;
}
>> GKwU msL¨vi eM©gj
~ wbY©‡qi Rb¨ wm †cÖvMÖvg wjL|
#include <stdio.h> Output
#include <math.h> 4
int main() Square root= 2.00000
{
double x, y;
scanf("%lf", &x);
y=sqrt(x);
printf("Square root=%lf", y);
return 0;
}
>> x Gi NvZ y wbY©‡qi Rb¨ wm †cÖvMÖvg wjL/ xy wbY©‡qi Rb¨ wm †cÖvMÖvg wjL|
#include <stdio.h> Output
#include <math.h> 53
int main() 125.00000
{
double x, y, p;
scanf("%lf %lf", &x,&y);
p=pow(x,y);
printf("%lf", p);
return 0;
}

** main() dvsk‡bi ‡k‡l return 0; †Kb e¨envi Kiv nq?

main() dvskb wm Gi cÖavb dvskb| wm fvlvq †Kvb †cÖvMÖvg ivb Ki‡j †Kv‡Wi †fZi main() dvskb ‡_‡K ‡cÖvMÖvgwU Pjv ïiæ
nq Ges K¤úvBjvi †cÖvMÖvg wbe©vn ‡k‡l GKwU Bw›URvi wiUvb© K‡i _v‡K| hv wbwðZ K‡i †cÖvMÖvgwU wVKfv‡e †Kvb mgm¨v QvovB
wbe©vn n‡q‡Q| cÖPwjZ wbq‡g 0 wiUvb© Kiv nq| Z‡e 0 Gi cwie‡Z© Ab¨ ‡h †Kvb Bw›URvi wiUvb© Kiv hvq|
** †cÖvMÖv‡g GKwU dvskb e¨envi Ki‡Z n‡j wZbwU wRwbm Rvb‡Z nq|
1. dvskbwU Kx KvR K‡i
2. dvsk‡bi †fZ‡i Kx Kx WvUv cvVv‡Z n‡e
3. dvskbwU wK WvUv wiUvb© K‡i
** `ywU w÷ªs mgvb bvwK eo-‡QvU ev `ywU w÷ªs Zzjbv Kivi Rb¨ strcmp() dvskbwU e¨envi Kiv nq|
** Zzjbv ev eo-‡QvU A_© n‡jv ˆ`‡N¨© eo ev †QvU bq| wWKkbvwi ev AvwfavwbK µ‡g mvRv‡j †h w÷ªswU Av‡M Avm‡e Zv‡K †QvU
Ges †hwU c‡i Avm‡e †mwU eo e‡j we‡ePbv Kiv| hv †jwK&ª‡KvMÖvwdK¨vwj (Lexicographically) bv‡g cwiwPZ|
D`vniY:
#include <stdio.h> Output
#include <string.h> Six Eight
int main() Six is greater than Eight.
{
char s1[80], s2[80]; home house
int value; home is smaller than house.
scanf("%s %s", s1, s2);
value= strcmp(s1, s2); five five
if(value==0) five and five are equal.
{
printf("%s and %s are equal.\n", s1, s2);
}
else if(value>0)
{
printf("%s is greater than %s.\n", s1, s2);
}
else
{
printf("%s is smaller than %s.\n", s1, s2);
}
return 0;
}

You might also like